Split into groups for your show
By the end of the week you will know how to use, LEDs, multicolor LEDs, Motors, Servos, and Stepper motors. You can plan your animatronic around using those parts
We start today by planning your show and who will make what. You can start making your skits for the show. Design your puppets and what you want to use the lights on for your show.
We start today by planning your show and who will make what. You can start making your skits for the show. Design your puppets and what you want to use the lights on for your show.
Multicolor LED
Set up your breadboard similar to as shown and use the 220 resistors for your board.
Getting the colors on (Blinking)
Use the same code that you used to get your regular LEDs on and off and see if you can get them to turn on the Multi color LED's colors. You may have to change the pin numbers used in your code. If you have trouble, you can start with this code below.
Now that you got one light on, go ahead and change your code to try and change colors or get two colors on at once.
Set Colors your own color
This code is used to set up your led to be multiple colors and brightness at once.
You change the numbers in the "setColor(255, 0, 0);" part to change what colors your LED makes.
You change the numbers in the "setColor(255, 0, 0);" part to change what colors your LED makes.
Getting the colors to switch
Now that you have gotten the code to work, try adding the other colors to digitalWrites to get the colors to switch.
You add this to the loop just like you added delays and more digitalWrites to your blink code.
You add this to the loop just like you added delays and more digitalWrites to your blink code.
Once you get it to work, change the values in the set color part to numbers between 0-255 and see what happens.
Getting the colors to fade
See if you can get your RGB LED to fade in and out with this code. Let's see if we can understand it too.
#define BLUE 3 //We are defining the different colors
#define GREEN 5 //to the different pins
#define RED 6 // change the numbers to what you have plugged in
void setup(){
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
}
int redValue; // define variables
int greenValue;
int blueValue;
void loop(){
#define delayTime 10 // fading time between colors
redValue = 255; // this code starts with red on, choose a value between 1 and 255 to change the color.
greenValue = 0;
blueValue = 0;
for(int i = 0; i < 255; i += 1) { // fades out red bring green full when i=255
redValue -= 1; // makes red dimmer by one each delay time
greenValue += 1; // makes green brighter by one each delay time
analogWrite(RED, redValue);
analogWrite(GREEN, greenValue);
delay(delayTime);
}
for(int i = 0; i < 255; i += 1) { // fades out green bring blue full when i=255
greenValue -= 1;
blueValue += 1;
analogWrite(GREEN, greenValue);
analogWrite(BLUE, blueValue);
delay(delayTime);
}
for(int i = 0; i < 255; i += 1) {// fades out blue bring red full when i=255
blueValue -= 1;
redValue += 1;
analogWrite(BLUE, blueValue);
analogWrite(RED, redValue);
delay(delayTime);
}
}
#define BLUE 3 //We are defining the different colors
#define GREEN 5 //to the different pins
#define RED 6 // change the numbers to what you have plugged in
void setup(){
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
}
int redValue; // define variables
int greenValue;
int blueValue;
void loop(){
#define delayTime 10 // fading time between colors
redValue = 255; // this code starts with red on, choose a value between 1 and 255 to change the color.
greenValue = 0;
blueValue = 0;
for(int i = 0; i < 255; i += 1) { // fades out red bring green full when i=255
redValue -= 1; // makes red dimmer by one each delay time
greenValue += 1; // makes green brighter by one each delay time
analogWrite(RED, redValue);
analogWrite(GREEN, greenValue);
delay(delayTime);
}
for(int i = 0; i < 255; i += 1) { // fades out green bring blue full when i=255
greenValue -= 1;
blueValue += 1;
analogWrite(GREEN, greenValue);
analogWrite(BLUE, blueValue);
delay(delayTime);
}
for(int i = 0; i < 255; i += 1) {// fades out blue bring red full when i=255
blueValue -= 1;
redValue += 1;
analogWrite(BLUE, blueValue);
analogWrite(RED, redValue);
delay(delayTime);
}
}
The Keypad
In order to make things work with your robot when you want you will need to hook up a keypad to control it. We will now make a new arduino file with the keypad code so that we can add code to it as we make things work.
Set up the keypad as shown to your Arduino.
Set up the keypad as shown to your Arduino.
Before we can use the keypad we need to make sure your arduino file has the correct library.
Go to: Sketch- Include Library - Manage Libraries -
Then type Keypad and check if the one by Mark Stanley is installed. If so continue on.
Go to: Sketch- Include Library - Manage Libraries -
Then type Keypad and check if the one by Mark Stanley is installed. If so continue on.
Here is the base code for the keypad
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'}, //define the symbols on the buttons of the keypads
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); //initializes Keypad
void setup(){
}
void loop (){
char customKey = customKeypad.getKey();
}
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'}, //define the symbols on the buttons of the keypads
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); //initializes Keypad
void setup(){
}
void loop (){
char customKey = customKeypad.getKey();
}
Test if your keypad works!
Every code you write can be added to work with your keypad by copying each part of your code and moving it to your keypad code. Add the below code into void loop () { }. In the if { } of the below code, put the premade code that you want button x to do in the { }.
if (customKey == 'x'){ //where x is what key you want to press to turn it on or off
}
Here is my example code to add you your loop to get your onboard LED to turn on or off
If it does not work make sure you check your blink code to make sure you added all the parts
void loop (){
char customKey = customKeypad.getKey();
if (customKey == '1'){
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
}
if (customKey == '2'){
digitalWrite(LED_BUILTIN, LOW);
}
}
See if you can get your multicolor LED to work with the buttons. Setting up all three colors to work by turning on and off with the keypad can make up to 7 colors. Red, Green, Blue, Cyan, Magenta, Yellow, and White.
if (customKey == 'x'){ //where x is what key you want to press to turn it on or off
}
Here is my example code to add you your loop to get your onboard LED to turn on or off
If it does not work make sure you check your blink code to make sure you added all the parts
void loop (){
char customKey = customKeypad.getKey();
if (customKey == '1'){
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
}
if (customKey == '2'){
digitalWrite(LED_BUILTIN, LOW);
}
}
See if you can get your multicolor LED to work with the buttons. Setting up all three colors to work by turning on and off with the keypad can make up to 7 colors. Red, Green, Blue, Cyan, Magenta, Yellow, and White.