I am only a few days into programing with Arduino and am loosing too much sleep:-( i have programed PLC’s to do what i want but in a ladder format and it is a bit confusing trying to do it with Arduino but i want to learn as i can think of dozens of uses for them.
so anyway i am trying to make 7x leds go off (LOW) one at a time from left to right when a button (inPut 1) is pressed then come back on after 30sec in the order they went off
then when button 2 (inPut 2) is pressed do the same thing but from right to left, then come back on after 30sec in the order they went off
and when button 3 (inPut 3) is pressed do the same thing but from the center out, then come back on after 30sec in the order they went off
i would like to have a pot on inPut 0 that controls the speed at witch they go off/back on (but i think i can figure this part out)
i have been trying to figure out how to setup multiple buttons (i can’t find anything in the learning section on multiple buttons?)
but here is some code i am playing with. i know i am not doing this right but i am trying to understand things so i am starting simple and trying to find things others have made to see how they work
int led1Pin = 13; // choose the pin for the 1 LED
int led2Pin = 12; // choose the pin for the 2 LED
int led3Pin = 11; // choose the pin for the 3 LED
int led4Pin = 10; // choose the pin for the 4 LED
int input1Pin = 1; // choose the input pin (for pushbutton 1)
int input2Pin = 2; // choose the input pin (for pushbutton 2)
int input3Pin = 3; // choose the input pin (for pushbutton 3)
int input4Pin = 4; // choose the input pin (for pushbutton 4)
int val1 = 0; // variable for reading the pin status
int val2 = 1; // variable for reading the pin status
int val3 = 2; // variable for reading the pin status
int val4 = 3; // variable for reading the pin status
void setup() {
pinMode(led1Pin, OUTPUT); // declare LED 1 as output
pinMode(led2Pin, OUTPUT); // declare LED 2 as output
pinMode(led3Pin, OUTPUT); // declare LED 3 as output
pinMode(led4Pin, OUTPUT); // declare LED 4 as output
pinMode(input1Pin, INPUT); // declare pushbutton 1 as input
pinMode(input2Pin, INPUT); // declare pushbutton 2 as input
pinMode(input3Pin, INPUT); // declare pushbutton 3 as input
pinMode(input4Pin, INPUT); // declare pushbutton 4 as input
digitalWrite(input1Pin, HIGH);
digitalWrite(input2Pin, HIGH);
digitalWrite(input3Pin, HIGH);
digitalWrite(input4Pin, HIGH);
}
void loop(){
val1 = digitalRead(input1Pin); // read input value
if (val1 == HIGH) { // check if the input is HIGH
digitalWrite(led1Pin, LOW); // turn LED OFF
} else {
digitalWrite(led1Pin, HIGH); // turn LED ON
}
val2 = digitalRead(input2Pin); // read input value
if (val2 == HIGH) { // check if the input is HIGH
digitalWrite(led2Pin, LOW); // turn LED OFF
} else {
digitalWrite(led2Pin, HIGH); // turn LED ON
}
val3 = digitalRead(input3Pin); // read input value
if (val3 == HIGH) { // check if the input is HIGH
digitalWrite(led3Pin, LOW); // turn LED OFF
} else {
digitalWrite(led3Pin, HIGH); // turn LED ON
}
val4 = digitalRead(input4Pin); // read input value
if (val4 == HIGH) { // check if the input is HIGH
digitalWrite(led4Pin, LOW); // turn LED OFF
} else {
digitalWrite(led4Pin, HIGH); // turn LED ON
}
}
This code is along the right idea for my project so i think if i can get the buttons figured out i can add some (if/else) code in here and maybe make it work
/*
- Knight Rider Overkill
- By wiring a potentiometer to analog inputs 0 and 1 I can adjust the
- speed and brightness.
- In ASCII art the extra wiring looks something like this:
- ±+ potentiometer
- |0|
- ±+
- / | \
- 5v | Gnd
- |
- inputPin
*/
int speedPin = 0; // pin to read the potentiometer for speed
int intenPin = 1; // pin to read the potentiometer for brightness
#define NUMLIGHTS 5
int pins[NUMLIGHTS] = { 5, 6, 9, 10, 11 };
void setup()
{
int lightPin;
for (lightPin=0 ; lightPin < NUMLIGHTS ; lightPin++) {
pinMode(pins[lightPin], OUTPUT);
}
}
void loop()
{
static int pos = 0; // the position of the brightest light in the light array
static int direction = 1; // the direction the bright spot is travelling (1 or -1)
int light;
int speed = analogRead(speedPin); // how fast the light moves
int inten = analogRead(intenPin) >> 2; // read the value and divide by 4 to get range 0 … 255
if (inten > 255) inten = 255;
for (light=0 ; light < NUMLIGHTS ; light++) {
if (light == pos) { // The light at this position is set bright
analogWrite(pins[light], inten);
} else if ( light == (pos+1) || light == (pos-1)) {
// This makes the two lights adjacent to the bright one glow at reduced intensity.
// It makes for a nicer effect
analogWrite(pins[light], inten>>4);
} else {
// Digital I/O pins 5 & 6 don’t seem to go dark if I do analogWrite(pins[light], 0)
// By doing digitalWrite it all looks correct
digitalWrite(pins[light], 0);
}
}
// move the light position
pos += direction;
// if we’ve reached the end, reverse directions
if (pos >= (NUMLIGHTS-1)) direction = -1;
if (pos <= 0) direction = 1;
delay(speed);
}
also if i get this figured out for my next project i would like to know if you can set a button to learn an IR code then map it to buttons?