Hi all,
Im writing some code (attached below) that is supposed to control an RGB led.
Whats supposed to happen is that you put the "device" into programming mode with a switch (pgrmPin) and then using 2 up/down buttons per led color select the color. so far nothing is happening.
The final version is meant to run on an attiny2313 that has a ported Arduino bootloader, thats why the pins are set the way they are. I have tried however to change the pin and run it on my Duemlinanove but still no success.
(yes the leds and buttons work)
if anyone can help it would be really appreciated.
Nadav.
const int redPin = 13; //Define red led
const int greenPin = 12;//Define green led
const int bluePin = 11;//Define blue led
const int pgrmPin = 10;//Define program switch
const int pgrmRUPin = 7;//Define red up button
const int pgrmGUPin = 6;//Define green up button
const int pgrmBUPin = 5;//Define blue up button
const int pgrmRDPin = 4;//Define red down button
const int pgrmGDPin = 3;//Define green down button
const int pgrmBDPin = 2;//Define blue down button
int red = 0;
int blue = 0;
int green = 0;
void setup() {
pinMode(redPin, OUTPUT); //PWM PIN 13 (PB4)
pinMode(greenPin, OUTPUT); //PWM PIN 12 (PB3)
pinMode(bluePin, OUTPUT); //PWM PIN 11 (PB2)
pinMode(pgrmPin, INPUT); //Digital PIN 10 (PB1)
pinMode(pgrmRUPin, INPUT); //Digital PIN 7 (PD5)
pinMode(pgrmGUPin, INPUT); //Digital PIN 6 (PD4)
pinMode(pgrmBUPin, INPUT); //Digital PIN 5 (PD3)
pinMode(pgrmRDPin, INPUT); //Digital PIN 4 (PD2)
pinMode(pgrmGDPin, INPUT); //Digital PIN 3 (PA0)
pinMode(pgrmBDPin, INPUT); //Digital PIN 2 (PA1)
}
void loop() {
if (pgrmPin == HIGH){//Enter Program mode
if (pgrmRUPin == HIGH && red >= 0 && red < 255){
red++;
}
if (pgrmRDPin == HIGH && red > 0 && red <= 255){
red--;
}
if (pgrmGUPin == HIGH && green >= 0 && green < 255){
green++;
}
if (pgrmGDPin == HIGH && green > 0 && green <= 255){
green--;
}
if (pgrmBUPin == HIGH && blue >= 0 && blue < 255){
blue++;
}
if (pgrmBDPin == HIGH && blue > 0 && blue <= 255){
blue--;
}
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}