My code://----------------------Info------------------------//
// Coded by The Sinding //
// 19-01-2011 //
// Project: RGB light //
//--------------------------------------------------//
//----------------Included libray-------------------//
#include <Keypad.h>
//----------------Rows and Colloms------------------//
const byte myRows = 4;
const byte myCols = 3;
//----------------Keypad setup----------------------//
char keys[myRows][myCols] =
{
{'*','0','*'},
{'7','8','9'},
{'4','5','6'},
{'1','2','3'},
};
//--------------------Pin setup---------------------//
byte rowPins[myRows] = {A5, A4, A3, A2}; //array to map keypad to MCU pins
byte colPins[myCols] = {12, 8, 7}; //array to map keypad to MCU pins
//------initialize an instance of class NewKeypad---//
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, myRows, myCols );
//------------------Define Led Pins-----------------//
#define RedPin 11
#define BluePin 10
#define GreenPin 9
#define redPin 6
#define greenPin 5
#define bluePin 3
//---------------------int--------------------------//
int BlackState;
//--------------------------------------------------//
void setup()
{
//----Set the arduino to send data over band 9600---//
Serial.begin(9600);
//------Set the green, red and blue pin to output---//
pinMode(GreenPin, OUTPUT);
pinMode(BluePin, OUTPUT);
pinMode(RedPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(redPin, OUTPUT);
}
void loop()
{
{
//--------------This is the basic state-------------//
while (BlackState);
{
//-When the key * is press, it resets to blackstate-//
char key = kpd.getKey();
if (key=='*')
{
//---------This is what it do when you press *------//
//---------It prints the line to the serial---------//
Serial.println("The leds is off");
//----------Sets the all the pins to LOW------------//
digitalWrite(GreenPin, LOW);
digitalWrite(RedPin, LOW);
digitalWrite(BluePin, LOW);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
delay(1);
}
//-------This what happens when you press 1---------//
if (key=='1')
{
//---------It prints the line to the serial---------//
Serial.println("The color is now red");
//-----------It sets the redpin to HIGH-------------//
digitalWrite(GreenPin, LOW);
digitalWrite(RedPin, HIGH);
digitalWrite(BluePin, LOW);
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
delay(1);
}
//-------This what happens when you press 2---------//
if (key=='2')
{
//---------It prints the line to the serial---------//
Serial.println("The color is now green");
//---------It sets the Greenpin to HIGH-------------//
digitalWrite(GreenPin, HIGH);
digitalWrite(RedPin, LOW);
digitalWrite(BluePin, LOW);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);
delay(1);
}
//-------This what happens when you press 3---------//
if (key=='3')
{
//---------It prints the line to the serial---------//
Serial.println("The color is now blue");
//---------It sets the Bluepin to HIGH--------------//
digitalWrite(GreenPin, LOW);
digitalWrite(RedPin, LOW);
digitalWrite(BluePin, HIGH);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);
delay(1);
}
//-------This what happens when you press 4---------//
if (key=='4')
{
//---------It prints the line to the serial---------//
Serial.println("The color is now cyan");
//------It sets the blue and green pin to HIGH------//
digitalWrite(GreenPin, HIGH);
digitalWrite(RedPin, LOW);
digitalWrite(BluePin, HIGH);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
delay(1);
}
//-------This what happens when you press 5---------//
if (key=='5')
{
//---------It prints the line to the serial---------//
Serial.println("The color is now purple");
//------It sets the blue and red pin to HIGH--------//
digitalWrite(GreenPin, LOW);
digitalWrite(RedPin, HIGH);
digitalWrite(BluePin, HIGH);
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);
delay(1);
}
//-------This what happens when you press 6---------//
if (key=='6')
{
//---------It prints the line to the serial---------//
Serial.println("The color is now yellow");
//-----It sets the green and red pin to HIGH--------//
digitalWrite(GreenPin, HIGH);
digitalWrite(RedPin, HIGH);
digitalWrite(BluePin, LOW);
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);
delay(1);
}
//-------This what happens when you press 7---------//
if (key=='7')
{
//---------It prints the line to the serial---------//
Serial.println("The color is now white");
//--It sets the green, blue and red pin to HIGH-----//
digitalWrite(GreenPin, HIGH);
digitalWrite(RedPin, HIGH);
digitalWrite(BluePin, HIGH);
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
delay(1);
}
//-------This what happens when you press 7---------//
if (key=='8')
{
{
//---------It prints the line to the serial---------//
Serial.println("It fades between colors");
//---------Now it sets all the pins to low----------//
digitalWrite(GreenPin, LOW);
digitalWrite(RedPin, LOW);
digitalWrite(BluePin, LOW);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
delay(1);
//-------Then it fades between differnt colors------//
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=10)
{
analogWrite(RedPin, fadeValue);
delay(45);
}
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=10)
{
analogWrite(RedPin, fadeValue);
delay(45);
}
for(int fadeValue = 0 ; fadeValue <=255; fadeValue +=10)
{
analogWrite(BluePin, fadeValue);
delay(45);
}
for(int fadeValue = 255 ; fadeValue >=0; fadeValue -=10)
{
analogWrite(BluePin, fadeValue);
delay(45);
}
for(int fadeValue = 0 ; fadeValue <=255; fadeValue +=10)
{
analogWrite(GreenPin, fadeValue);
delay(45);
}
for(int fadeValue = 255 ; fadeValue >=0; fadeValue -=10)
{
analogWrite(GreenPin, fadeValue);
delay(45);
}
for(int fadeValue = 0 ; fadeValue <=255; fadeValue +=10)
{
analogWrite(BluePin, fadeValue);
analogWrite(GreenPin, fadeValue);
delay(45);
}
for(int fadeValue = 255 ; fadeValue >=0; fadeValue -=10)
{
analogWrite(BluePin, fadeValue);
analogWrite(GreenPin, fadeValue);
delay(45);
}
for(int fadeValue = 0 ; fadeValue <=255; fadeValue +=10)
{
analogWrite(BluePin, fadeValue);
analogWrite(RedPin, fadeValue);
delay(45);
}
for(int fadeValue = 255 ; fadeValue >=0; fadeValue -=10)
{
analogWrite(BluePin, fadeValue);
analogWrite(RedPin, fadeValue);
delay(45);
}
for(int fadeValue = 0 ; fadeValue <=255; fadeValue +=10)
{
analogWrite(RedPin, fadeValue);
analogWrite(GreenPin, fadeValue);
delay(45);
}
for(int fadeValue = 255 ; fadeValue >=0; fadeValue -=10)
{
analogWrite(RedPin, fadeValue);
analogWrite(GreenPin, fadeValue);
delay(45);
}
for(int fadeValue = 0 ; fadeValue <=255; fadeValue +=10)
{
analogWrite(RedPin, fadeValue);
analogWrite(GreenPin, fadeValue);
analogWrite(BluePin, fadeValue);
delay(45);
}
for(int fadeValue = 255 ; fadeValue >=0; fadeValue -=10)
{
analogWrite(RedPin, fadeValue);
analogWrite(GreenPin, fadeValue);
analogWrite(BluePin, fadeValue);
delay(45);
}
}
}
}
}
}
//-------------Now the script ends-----------------//
Did someone created something similar or something that I can look at?