Tuesday 8 December 2015

Challenge 7 - Buzzer

Challenge Name: most annoying thing ever

author: kyle

credit: i reference the code off newinnovators,ca

difficulty level: 4

time to complete: 7 minutes

Challenge description: Make the buzzer buzz a sequence of high notes


























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 = 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[] = { 900, 1319, 1000, 354, 976, 836, 385, 656 };
   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);  
   }
 }

Lab 7 - Buzzer

Purpose:
To make the buzzer buzz the tune of 'Twinkle Twinkle Little Star'

Equipment:
Piezo Element (x1)
wires (x4)

Program Details:
i used the one off newinnovators.ca

Time to Program and Complete:
5 mintues

Results:
N/A



Photo/Video Proof:



























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:
N/A

Helpful Tips:
Make sure positive is positive

References:
nweinnovators.ca

Monday 7 December 2015

Challenge 6 - Light Sensor

Challenge Name: Lights Changing

Name: Kyle Chan

Credit: i referenced the code of newinnovators.ca

Difficulty Level: 4

Time to complete: 7 minutes

Challenge description: One led turns on when the sensor is covered and another turns on when it is not

Hint:

Answer:
int lightPin = 0;
int ledPin = 9;
int ledPin1 = 10;

void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(lightPin, INPUT);
}

void loop()
{
  int lightLevel = analogRead(lightPin);
  lightLevel = map(lightLevel, 0, 900, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);
  
  if (lightLevel < 900);
  {
    digitalWrite (ledPin, HIGH);
    digitalWrite (ledPin1, LOW);
  }
  else if (lightLevel > 900);
  {
    digitalWrite (ledPin1, HIGH);
    digitalWrite (ledPin, LOW);
  }
}

Challenge 5 - RGB LED

Challenge Name: Multi Coloured

Name: Kyle Chan

Credit: I reference the code of newinnovators.ca

Difficulty Level: 3

Time to Complete: 5 minutes

Hint: The colour changes faster

Challenge description: The RGB LED switches between different colours on it's own


























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

int redIntensity = 0;
int greenIntensity = 0;
int blueIntensity = 0;

const int DISPLAY_TIME = 50;

void setup()
{
}
void loop()
{
  for (greenIntensity = 0; greenIntensity <= 255; greenIntensity+=5)
  {
    redIntensity = 255-greenIntensity;
    analogWrite(GREEN_LED_PIN, greenIntensity);
    analogWrite(RED_LED_PIN, redIntensity);
    delay(DISPLAY_TIME);
  }
  for (blueIntensity = 0; blueIntensity <= 255; blueIntensity+=5)
  {
    greenIntensity = 255-blueIntensity;
    analogWrite(BLUE_LED_PIN, blueIntensity);
    analogWrite(GREEN_LED_PIN, greenIntensity);
    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);
  }
}
  }
}

Tuesday 1 December 2015

Challenge 4 - Potentiometer

Challenge NameLIGHTS
AuthorKyle Chan
Creditnewinnovators.ca
Difficulty Level (1-5)Level 3
Time To Complete5 minutes
Challenge Description














.
Hint
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);
                                }
 



Lab 6 - Light Sensor

Purpose:
Make the light turn on and off using the light sensor

Equipment:
Light sensor (x1)
resistor (10k Ohm) (x1)
LED
resistor (330 Ohm) (x1)
wire (x6)


Program Details:
I used the one off newinnovators.ca

Time to Program and Complete:
5 minutes

Results:
N/A

Photo/Video Proof:




























Program
int lightPin = 0;
//sets a value for lightPin
int ledPin = 9;
//sets a value for ledPin

void setup()
//declares a setup
{
  pinMode(ledPin, OUTPUT);
//sets ledPin as an output
}

void loop()
//declares a setup
{
//start of loop
  int lightLevel = analogRead(lightPin);
//introduces a new variable; lightLevel
  lightLevel = map(lightLevel, 0, 900, 0, 255);
//lightLevel is equal to...
  lightLevel = constrain(lightLevel, 0, 255);
//sets a new value for lightLevel
  analogWrite(ledPin, lightLevel);
//turns on ledPin for a value of lightLevel

}
//end of loop

Program Modifications:
N/A

Helpful Tips:


References:
newinnovators.ca

Monday 30 November 2015

Lab 5 - RGB LED

Purpose:
Utilize the RGB LED to made it shift colours

Equipment:
RGB LED (x1)
resistor (x1)
wires (x3)

Program Details:
i used the one off newinnovators.ca

Time to Program and Complete:
3 minutes

Results:
N/A

Photo/Video Proof:








































Program:
const int RED_LED_PIN = 9;
//sets a constant value for RED_LED_PIN
const int GREEN_LED_PIN = 10;
//sets a constant value for GREEN_LED_PIN
const int BLUE_LED_PIN = 11;
//sets a constant value for BLUE_LED_PIN

int redIntensity = 0;
//sets value for redIntensity
int greenIntensity = 0;
//sets value for redIntensity
int blueIntensity = 0;
//sets value for redIntensity

const int DISPLAY_TIME = 
//sets constant value for DISPLAY_TIME

void setup()
{
}
void loop()
//declares action
{
//start of loop
  for (greenIntensity = 0; greenIntensity <= 255; greenIntensity+=5)
//if conditions met continue code
  {
//loop inside of loop
    redIntensity = 255-greenIntensity;
//sets new value for redIntensity
    analogWrite(GREEN_LED_PIN, greenIntensity);
//turns on GREEN_LED_PIN to value greenIntensity
    analogWrite(RED_LED_PIN, redIntensity);
//turns on RED_LED_PIN to value of redIntensity
    delay(DISPLAY_TIME);
//delay time for value for DISPLAY_TIME
  }
// end loop
  for (blueIntensity = 0; blueIntensity <= 255; blueIntensity+=5)
//if conditions met continue code
  {
//loop inside of loop
    greenIntensity = 255-blueIntensity;
//sets new value for greenIntensity
    analogWrite(BLUE_LED_PIN, blueIntensity);
//turns on BLUE_PIN to value bluensity
    analogWrite(GREEN_LED_PIN, greenIntensity);
//turns on GREEN_LED_PIN to value greenIntensity
    delay(DISPLAY_TIME);
//delay time for value for DISPLAY_TIME
  }
//end of loop
  for (redIntensity = 0; redIntensity <= 255; redIntensity+=5)
//if conditions met continue code
  {
//loop inside of loop
    blueIntensity = 255-redIntensity;
//sets new value for blueIntensity
    analogWrite(RED_LED_PIN, redIntensity);
//turns on RED_PIN to value redIntensity
    analogWrite(BLUE_LED_PIN, blueIntensity);
//turns on BLUE_PIN to value blueIntensity
    delay(DISPLAY_TIME);
//delay time for value for DISPLAY_TIME
  }
//end of loop
}


//end of loop
Program Modifications:
N/A

Helpful Tips:


References:
newinnovators.ca