Thursday, 10 December 2015

Arduino Challenge 6

Challenge Name
Off and On lights

Author
Joshua Mac

Credit
Aron Graca, Kyle Chan, Carl Villamor

Difficulty Level (1-5)
4

Time to Complete
30 mins

Challenge Description
Have a light sensor turn on 2 Leds

Answer
int lightPin = 0;
int ledPin = 9;
int ledPin2 = 8;

void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
}

void loop()
{
  int lightLevel = analogRead(lightPin);
  lightLevel = map(lightLevel, 0, 900, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);
  analogWrite(ledPin, lightLevel);
  analogWrite(ledPin2, lightLevel);
}

Wednesday, 9 December 2015

Arduino Challenge 7

Challenge Name:
Happy Music

Author:
Joshua Mac

Credit:
Aron Graca, Kyle Chan, Si-weon Woo

Difficulty level:
4

Time to Complete:
30 Mins

Challenge description:
 To make music with the piezo element play faster.
Answer:
int speakerPin = 9;
int length = 15;
char notes[] = "ccggaagffeeddc ";
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4};
int tempo = 100;

void playTone(int tone, int duration)
{
  for (long i = 0; i < duration * 1000L; i += tone * 2)
  {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin,LOW);
    
  }
}
void playNote(char note, int duration)
{
  char names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = {1300, 1900, 1589, 1483, 1700, 1436, 1903, 912};
  for (int i = 0; i < 8; i++)
  {
    if (names[i] == note)
    {
      playTone(tones[i], duration);
    }
  }
}

void setup()
{
  pinMode(speakerPin, OUTPUT);
}

void loop()
{
  for (int i = 0; i < length; i++)
  {
    if (notes[i] == ' ')
    {
      delay(beats[i] * tempo);
    }
    else
    {
      playNote(notes[i], beats[i] * tempo);
    }
    delay(tempo / 2);
  }

Tuesday, 8 December 2015

ARDUINO Challenge 5

Challenge Name:
Flashy lights

Author:
Joshua Mac

Credit:
Aron Graca

Difficulty Level:
3

Time to Complete:
5mins

Challenge Description:
Make an RGB blink blue and red fast.

Hint:
None

Answer:
const int RED_LED_PIN = 9;
const int BLUE_LED_PIN = 11;

int redIntensity = 0;
int blueIntensity = 0;

const int DISPLAY_TIME = 10;

void setup()
{
}

void loop()
{
  for (blueIntensity = 0; blueIntensity <= 255; blueIntensity+=5)
  {
    redIntensity = 255-blueIntensity;
    analogWrite(BLUE_LED_PIN, blueIntensity);
    analogWrite(RED_LED_PIN, redIntensity);
    delay(DISPLAY_TIME);
  }
  for (redIntensity = 0; redIntensity <= 255; redIntensity+=5)

  {
    blueIntensity = 255-redIntensity;
    analogWrite(RED_LED_PIN, redIntensity);
    analogWrite(BLUE_LED_PIN, blueIntensity);
    delay(DISPLAY_TIME);

  }
}



Arduino Lab 7

Purpose:
 To make music with the piezo element.

Equipment:
Piezo element
2 wires (any colour)

Program Details:
Arduino

Time to Program and Complete:
20 mins

Results:
A lot of coding problems

Photo/Video Proof:
None right now

Program:
int speakerPin = 9;
int length = 15; 
char notes[] = "ccggaagffeeddc "; 
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;
void playTone(int tone, int duration) 
{
  for (long i = 0; i < duration * 1000L; i += tone * 2) 
  {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}
void playNote(char note, int duration) 
{
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
          int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
  for (int i = 0; i < 8; i++) 
  {
    if (names[i] == note) 
    {
      playTone(tones[i], duration);
    }
  }
}
void setup() 
{
  pinMode(speakerPin, OUTPUT);
}
void loop() 
{
  for (int i = 0; i < length; i++) 
  {
    if (notes[i] == ' ') 
    {
      delay(beats[i] * tempo);
    } 
    else 
    {
      playNote(notes[i], beats[i] * tempo);
    }
    delay(tempo / 2); 
  }
}

Program Modifications:
None

Helpful Tips:
None

References:
Aron Graca
Kyle chan

Monday, 7 December 2015

Arduino Challenge 4

Challenge Name
25%, 50
% 75% 100%!

Author
Joshua Mac

Credit
Aron Graca
Kyle Chan

Difficulty Level (1-5)
3

Time To Complete
15 mins\

Challenge DescriptionMake a circuit with LEDs in a row. The LEDs will light up one at a time in proportion with how far the potentiometer is twisted.

                              
Answer:
int sensorPin = A0;
int ledPin1 = 13;
int sensorValue = 0;
void setup()
 {  
pinMode(ledPin1, OUTPUT);
pinMode(sensorValue, INPUT);
}
void loop()
 {
 sensorValue = analogRead(sensorPin);
 digitalWrite (ledPin1, sensorPin);
 }

 

Friday, 4 December 2015

Arduino Challenge 3

Challenge Name:
Christmas Lights

Author:
Joshua Mac

Difficulty level (1-5)
3

Time to complete
20 mins

Reference
Aron Graca
Kyle Chan

Challenge Description
While pushing a button, the red lights go on.
when not pushing any buttons, the green lights go on.

Pictures:




















Answer
const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int ledPin1 = 10;
const int ledPin2 = 9;
const int ledPin4 = 11;
const int ledPin3 = 8;

int buttonState1 = 0;
int buttonState2 = 0;

void setup()
{
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
}

void loop()
{
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  if (buttonState1 == HIGH)
  {
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin4, HIGH);
    delay(1000);
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin4, LOW);
   
  }
  else if (buttonState2 == HIGH)
  {
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin3, HIGH);
    delay(1000);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
  }
}


Arduino Lab 5

Purpose
To make a RGB LED change colours

Equipment
-RGB LED
-330ohm resistor
-3 wires(any colour)

Program Details
Arduino

Time
10 mins

Results
LEDs were in wrong way

Photo/Video proof
None right now

Program
const int RED_LED_PIN = 9; -Creates a constant variable for Red led to pin 9
const int GREEN_LED_PIN = 10; -Creates a constant variable for Green led to pin 10
const int BLUE_LED_PIN = 11; -Creates a constant variable for Blue led to pin 11

int redIntensity = 0; -How much light would generate for the red led
int greenIntensity = 0; -How much light would generate for the green led
int blueIntensity = 0; --How much light would generate for the blue led

const int DISPLAY_TIME = 100; - -Creates a constant variable for time
void setup()- there is no void setup
{
}

void loop() -Starting the void loop()
{-Start of void loop()
  for (greenIntensity = 0; greenIntensity <= 255; greenIntensity+=5)-The value of green increases from 0-255 increasing by 5 each loop.
  {- Start of for loop
    redIntensity = 255-greenIntensity;- red led will adjust to green
    analogWrite(GREEN_LED_PIN, greenIntensity);-Power is given to green led
    analogWrite(RED_LED_PIN, redIntensity);--Power is given to red led
    delay(DISPLAY_TIME); -pauses the program for a bit
  }-end of for loop
  for (blueIntensity = 0; blueIntensity <= 255; blueIntensity+=5)-The value of  blue increases from 0-255 increasing by 5 each loop.
  {-Start of for loop
    greenIntensity = 255-blueIntensity;-green led will adjust to blue
    analogWrite(BLUE_LED_PIN, blueIntensity);-Power is given to blue led
    analogWrite(GREEN_LED_PIN, greenIntensity);-Power is given to green led
    delay(DISPLAY_TIME); -pauses the program for a bit
  }-End of for loop
  for (redIntensity = 0; redIntensity <= 255; redIntensity+=5)The value of red increases from 0-255 increasing by 5 each loop.
  {-Start of for loop
    blueIntensity = 255-redIntensity; -blue led will adjust to red
    analogWrite(RED_LED_PIN, redIntensity);-Power is given to red led
    analogWrite(BLUE_LED_PIN, blueIntensity);-Power is given to blue led
    delay(DISPLAY_TIME); -pauses the program for a bit
  }-End of for loop
}-End of program

Program Modifications:
none

Helpful Tips:
Don't put LEDs in the wrong way

References:
Aron Graca

Kyle Chan

Thursday, 3 December 2015

Arduino Lab 3 Part 2

Purpose:
 Use a second button so one turns it on, and the other turns it off.

Equipment:
Push button
330 Ohm resistor 
3 Led's (Any color)

Program Details:
Arduino

Time to Program and Complete:
10mins

Results:
No problems

Photo/Video Proof:
None right now

Program:
int led = 9; -This makes a variable called led which holds a value of 9
int onbutton = 3; -This makes a variable called onbutton which holds a value of 3
int offbutton = 2; -This makes a variable called offbutton which holds a value of 2

void setup () - void setup() is starting
{ - Start of void setup()
  pinMode(led, OUTPUT); -Declares led (pin 9) to be an Output
  pinMode(onbutton, INPUT); -Declares onbutton (pin 3) to be an input
  pinMode(offbutton, INPUT); -Declares offbutton (pin 2) to be an input
- End of void setup()

void loop () -void loop() is starting
{ -Start of void loop()
  if (digitalRead(offbutton) == LOW)
  { -Start of if statement
    digitalWrite(led, LOW);
  } - End of if statement
  else if (digitalRead (onbutton) == LOW)
  {-Start of else statement
    digitalWrite(led, HIGH);
  }-End of else statement
}-End of program
Program Modifications:
None

Helpful Tips:
List any suggestions to make this easier for new users

References:
Aron Graca
Kyle Chan

Arduino Lab 3 part 1

Purpose:
 Make an LED turn on and off using one button.

Equipment:
LED (Any Colour)
6 Wires(Any Colour)
3 Resistors
Push button

Program Details:
Arduino

Time to Program and Complete:
15mins

Results:
-what problems did you have and how did you fix it?

Photo/Video Proof:
none right now

Program:
const int buttonPin = 2;
//makes a variable called buttonPin hold a value of 2. Const makes the variable constant and unchanging
const int ledPin = 9;
//makes a variable called ledPin hold a value of 9. Const makes the variable constant and unchanging

int buttonState = 0;
//makes a variable called buttonState with a value of 0

void setup()
//the code underneath is isolated from the other code
{
//anything underneath is part of the above code
  pinMode(ledPin, OUTPUT);
//identifies the ledPin as either and output or input
  pinMode(buttonPin, INPUT);
//identifies the buttonPin as either and output or input
}

void loop()
//the code underneath will loop continuously
{
//beginning of loop function
  buttonState = digitalRead(buttonPin);
//checks to see if a variable is true
  if (buttonState == HIGH)
//if buttonState is equal to HIGH
  {
//beginning of loop
    digitalWrite(ledPin, HIGH);
//gives power to ledPin 
  }
//ends loop
  else
//if the original condition is not true do this:
  {
//beginning of loop
    digitalWrite(ledPin, LOW);
//gives LOW power to ledPin
  }
//end loop
}
//end loop


Program Modifications:
None

Helpful Tips:
None

References:
Aron Graca
Kyle Chan

Arduino Lab 6

Purpose:
To make an LED change its brightness level according to how much light is hitting the light sensor

Equipment:
Light sensor
Led (any colour)
3 wires (any colour)
330 Ohm resistor
10k Ohm resistor


Program Details:
Arduino

Time to Program and Complete:
15 mins

Results:
We had no problems

Photo/Video Proof:
None right now

Program:
int lightPin = 0;  -Creates a variable for lightPin to pin 0

int ledPin = 9; -Creates a variable for ledPin to pin 9


void setup() -Starting of the void setup()
{   -Start of void setup()
  
pinMode(ledPin, OUTPUT);- Tells if the ledPin is an Output or Input
}   - End of void setup()

void loop()  -Start of void loop()
{   -Start of void loop()

 int lightLevel = analogRead(lightPin);  -Creates a variable for lightLevel which stores value from the light sensor
  
lightLevel = map(lightLevel, 0, 900, 0, 255); -Converts lightLevel from 0-900 to 0-255 

 l = constrain(lightLevel, 0, 255); -Makes sures light level is from 0-255

 analogWrite(ledPin, lightLevel);  -ledPin is = to lightLevel 
}   -End of program

Program Modifications:
none

Helpful Tips:
Not really anything

References:
Aron Graca