Hi everybody. I really do not have much experience with programming an arduino and hope you guys can help me if possible.
I only managed to successfully program one uno for a washing machine - drum spins clockwise, pause 3 seconds, drum spins counter clockwise - - hehe!
Here is the situation. I have a small little Opel corsa utility pickup. The car is very small with extremely limited space behind the dashboard so I can't fit latching switches for the aircon pump and 3 sets of spotlights. I need 4 switches - aircon, white spotlights, yellow spotlights and reverse gear spotlights. So I decided to install micro momentary switches which does not take a lot of space, which i will then run through an arduino micro or uno to switch each relay permanently on or off. I will use the 5V outputs to switch the relay drivers for each individual relay. So you will have something like this.... Switch 1 will latch relay driver for relay 1 which will handle the aircon pump. Switch 2 will latch relay driver for relay 2 which will handle the yellow fog lights,----- you get the picture up to switch 4. (reverse light spot light)
With me so far? Good.....
I found this code and it is working perfectly......
const unsigned int BUTTON_PIN = 7;
const unsigned int LED_PIN = 13;
int old_button_state = LOW;
int led_state = LOW;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT);
}
void loop() {
const int CURRENT_BUTTON_STATE = digitalRead(BUTTON_PIN);
if (CURRENT_BUTTON_STATE != old_button_state &&
CURRENT_BUTTON_STATE == HIGH)
{
led_state = (led_state == LOW ? HIGH : LOW);
digitalWrite(LED_PIN, led_state);
delay(50);
}
old_button_state = CURRENT_BUTTON_STATE;
}
This is perfect for what I want to do - I will just replace the led with an relay driver and relay. OK. Now I tried to add for now only one additional switch and LED (remember , I need 4 switches each operating it's own LED). So I tried to modified the code to look like this.......
const unsigned int BUTTON1_PIN = 2;
const unsigned int BUTTON2_PIN = 3;
const unsigned int LED_PIN1 = 13;
const unsigned int LED_PIN2 = 12;
int old_button_state = LOW;
int led_state = LOW;
void setup() {
pinMode(LED_PIN1, OUTPUT);
pinMode(LED_PIN2, OUTPUT);
pinMode(BUTTON1_PIN, INPUT);
pinMode(BUTTON2_PIN, INPUT);
}
void loop() {
const int CURRENT_BUTTON_STATE = digitalRead(BUTTON1_PIN);
if (CURRENT_BUTTON_STATE != old_button_state &&
CURRENT_BUTTON_STATE == HIGH)
{
led_state = (led_state == LOW ? HIGH : LOW);
digitalWrite(LED_PIN1, led_state);
delay(50);
}
old_button_state = CURRENT_BUTTON_STATE;
}
void loop() {
const int CURRENT_BUTTON_STATE = digitalRead(BUTTON2_PIN);
if (CURRENT_BUTTON_STATE != old_button_state &&
CURRENT_BUTTON_STATE == HIGH)
{
led_state = (led_state == LOW ? HIGH : LOW);
digitalWrite(LED_PIN2, led_state);
delay(50);
}
old_button_state = CURRENT_BUTTON_STATE;
}
Too bad it doesn't work, I get this.......... well I attached it hope it is on this post.....)
Any Ideas how to fix these 3 errors, any suggestions, help greatly appreciated!!!!
Thanks!
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.
2btn2ledARDUINOerror.bmp (1.13 MB)