Demo Coding Page Bumblebee

Blink Bumblebee's Eyes On and Off

//Blink Bumblebee's eyes at different speeds and different colors #include "LEDStrip.h" LEDStrip strip = LEDStrip(1, 13, 12); //Set up the LED pixel void setup() {} void loop() { strip.setPixel(0,200); //Set the eye pixel to a color value of 200. Colors range from 0-300 strip.draw(); //Send the color value to Bumblebee delay(1000); //Wait 1 second with the Bumblebee's eyes lit up strip.clear(); //Turn off the eye color strip.draw(); //Send the "off" command to Bumblebee delay(1000); //Wait 1 second before the loop starts again. }
 

Challenges

Can you complete the challenges? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!

 

//Fade through the colors of Bumblebee’s eyes

#include "LEDStrip.h" //The LEDStrip.h library gives your code access to special functions exclusive to the LED Strip

LEDStrip strip = LEDStrip(1, 13, 12); //Set up the strip by defining how many pixels (50) and which pins of the microchip are used (always 13 and 12 on Code Lab)

void setup() {

for(int i =8;i<12;i++){

pinMode(i,OUTPUT);

}

pinMode(6,INPUT_PULLUP);

pinMode(7,INPUT_PULLUP);

pinMode(A0,INPUT);

}

void loop() {

for(int i = 1;i<300;i++){

strip.setPixel(0,i);

strip.draw();

delay(5);

}

}

//Raise and lower the tone on Bumblebee with button presses

void setup() {

for(int i =8;i<12;i++){

pinMode(i,OUTPUT);

}

pinMode(6,INPUT_PULLUP);

pinMode(7,INPUT_PULLUP);

pinMode(A0,INPUT);

}

int pitch = 100;

void loop() {

if(digitalRead(6)==LOW){

pitch--;

delay(10);

tone(A5,pitch);

}

else if(digitalRead(7)==LOW){

pitch++;

delay(10);

tone(A5,pitch);

}

else{

noTone(A5);

}

}

//Press Button 6 to have Bumblebee make a decision between green (go) and red (no-go) lights

void setup() {

for(int i =8;i<12;i++){

pinMode(i,OUTPUT);

}

pinMode(6,INPUT_PULLUP);

pinMode(7,INPUT_PULLUP);

pinMode(A0,INPUT);

}

void loop() {

if(digitalRead(6)==LOW){

for(int i=1;i<random(10,30);i++){

digitalWrite(8,HIGH);

digitalWrite(9,LOW);

delay(150);

digitalWrite(8,LOW);

digitalWrite(9,HIGH);

delay(150);

}

digitalWrite(8,LOW);

digitalWrite(9,LOW);

digitalWrite(random(8,10),HIGH);

tone(A5,450);

delay(600);

noTone(A5);

}

}

//Tune Bumblebee's tone with the turn knob. Press Button 7 to play the tone

void setup() {

for(int i =8;i<12;i++){

pinMode(i,OUTPUT);

}

pinMode(6,INPUT_PULLUP);

pinMode(7,INPUT_PULLUP);

pinMode(A0,INPUT);

}

void loop() {

int pitch = analogRead(A0);

if(digitalRead(7)==LOW){

tone(A5,pitch);

}

else{

noTone(A5);

}

}