Hi this is my first post in the forum but i have been reading for a while now!
I have done a few projects with the arduino and have now started to write my own code for a project i would like to do
A simple LED Flasher with a mode select button i have written the code by looking at other projects and this is what i have come up with so far
// Mode 1 White leds on
// Mode 2 Flashing Red and blue + White Leds on
// Mode 3 Flashing Red and blue
// Mode 4 All flashing
int counter = 0; // set counter at 0 to start
int switchPin = 9; // define button pin
//define LED Pins
int LEDB = 10;
int LEDW = 11;
int LEDR = 12;
void setup()
{
pinMode(switchPin, INPUT);
pinMode(LEDR, OUTPUT);
pinMode(LEDW, OUTPUT);
pinMode(LEDB, OUTPUT);
}
void loop() {
//Handle input
int switchVal = digitalRead(switchPin);
if(switchVal == HIGH)
{
delay(500);
counter ++;
//Reset count if over max mode number
if(counter == 5)
{
counter = 0;
}
}
else
//Change mode
switch (counter) {
case 1:
digitalWrite(LEDW, HIGH); // set the LED on
break;
case 2:
digitalWrite(LEDW, HIGH); // set the LED on
digitalWrite(LEDR, HIGH); // set the LED on
delay(500); // wait for half a second
digitalWrite(LEDB, HIGH); // set the LED on
digitalWrite(LEDR, LOW); // set the LED off
delay(500); // wait for half a second
digitalWrite(LEDB, LOW); // set the LED off
break;
case 3:
digitalWrite(LEDW, HIGH); // set the LED on
delay(500); // wait for half a second
digitalWrite(LEDW, LOW); // set the LED off
digitalWrite(LEDR, HIGH); // set the LED on
delay(500); // wait for half a second
digitalWrite(LEDB, HIGH); // set the LED on
digitalWrite(LEDR, LOW); // set the LED off
delay(500); // wait for half a second
digitalWrite(LEDB, LOW); // set the LED off
break;
case 4:
digitalWrite(LEDR, HIGH); // set the LED on
delay(500); // wait for half a second
digitalWrite(LEDB, HIGH); // set the LED on
digitalWrite(LEDR, LOW); // set the LED off
delay(500); // wait for half a second
digitalWrite(LEDB, LOW); // set the LED off
break;
}
}
The problem I'm having is that it randomly changes modes doesn't stay in one mode but also does not display all modes it kinda jumps from all on or all flashing also i would like to run this on an Attiny13 in the end using the arduino IDE attiny13 core will this also work?
any help would be awesome
thanks
Jamie!
P.S sorry if in the wrong place?