Mike I posted the schematic up above. The code I am having issues with is 95% the same as what is posted, I have edited it and reposted it here:
// Button inputs:
const int underbuttonPin = A0; // the pin that the pushbutton is attached to
const int signbuttonPin = A1; // the pin that the pushbutton is attached to
// LED outputs:
const int GREENledPinWheat = 3; // the number of the green LED pin
const int BLUEledPinSun = 5; // the number of the blue LED pin
const int REDledPinRun = 6; // the number of the red LED pin
const int GREENledPinRun = 9; // the number of the green LED pin
const int BLUEledPinRun = 10; // the number of the blue LED pin
const int underledPin = 11; // the pin that the white LED is attached to
// Variables that will change:
int underbuttonPushCounter = 0; // counter for the number of button presses
int underbuttonState = 0; // current state of the button
int lastunderbuttonState = 0; // previous state of the button
int signbuttonPushCounter = 0; // counter for the number of button presses
int signbuttonState = 0; // current state of the button
int lastsignbuttonState = 0; // previous state of the button
void setup() {
// initialize the button pins as inputs:
pinMode(underbuttonPin, INPUT);
pinMode(signbuttonPin, INPUT);
// initialize the LED's as an outputs:
pinMode(GREENledPinWheat, OUTPUT);
pinMode(BLUEledPinSun, OUTPUT);
pinMode(REDledPinRun, OUTPUT);
pinMode(GREENledPinRun, OUTPUT);
pinMode(BLUEledPinRun, OUTPUT);
pinMode(underledPin, OUTPUT);
// initialize serial communication:
//Serial.begin(9600);
}
void loop() {
// read the undercabinet pushbutton input pin:
underbuttonState = digitalRead(underbuttonPin);
// compare the underbuttonState to its previous state
if (underbuttonState != lastunderbuttonState) {
// if the state has changed, increment the counter
if (underbuttonState == HIGH) {
// if the current state is HIGH then the button
// went from off to on:
underbuttonPushCounter++;
Serial.println("on");
Serial.print("number of left button pushes: ");
Serial.println(underbuttonPushCounter);
} else {
// if the current state is LOW then the button
// went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastunderbuttonState = underbuttonState;
// turns on the LED every two button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (underbuttonPushCounter % 2 == 0) {
digitalWrite(underledPin, LOW);
} else {
digitalWrite(underledPin, HIGH);
}
// read the sign pushbutton input pin:
signbuttonState = digitalRead(signbuttonPin);
// compare the signbuttonState to its previous state
if (signbuttonState != lastsignbuttonState) {
// if the state has changed, increment the counter
if (signbuttonState == HIGH) {
// if the current state is HIGH then the button
// went from off to on:
signbuttonPushCounter++;
Serial.println("on");
Serial.print("number of right button pushes: ");
Serial.println(signbuttonPushCounter);
} else {
// if the current state is LOW then the button
// went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastsignbuttonState = signbuttonState;
// turns on the LED every two button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (signbuttonPushCounter % 2 == 0) {
digitalWrite(GREENledPinWheat, LOW);
digitalWrite(BLUEledPinSun, LOW);
analogWrite(REDledPinRun, 0);
analogWrite(GREENledPinRun, 0);
analogWrite(BLUEledPinRun, 0);
Serial.println("SIGN OFF");
} else {
digitalWrite(GREENledPinWheat, HIGH);
digitalWrite(BLUEledPinSun, HIGH);
analogWrite(REDledPinRun, 100);
analogWrite(GREENledPinRun, 200);
analogWrite(BLUEledPinRun, 50);
Serial.println("SIGN ON");
}
}
The code is based off a pushbutton toggle state code that I snipped up and tried to make work. It works great for turning on and off a device (like the white LED's), however it doesn't work for the analogWrite. The Serial.printIn does flood the serial monitor window the way the code stands which is why I am assuming it is causing an issue with the analogWrite?
I have run the example Fade code and changed the LED pin to each 3, 5, 6, 9, 10 and 11 without issue.
/*
Fade
This example shows how to fade an LED on pin 9
using the analogWrite() function.
The analogWrite() function uses PWM, so if
you want to change the pin you're using, be
sure to use another PWM capable pin. On most
Arduino, the PWM pins are identified with
a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.
This example code is in the public domain.
*/
int led = 9; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}