Im having issues with my coding as my back ground was scripting with AHK and C++ coding this code aint working how i expected
tested each part to check that it works Read pins and write Pins witch all work , my debouce skills are very low so cant get that working and will need to use functions to do the programming with the 2 line display to finish my project
the first issue in my code , on button press it it turns 1 of then a second then both on , instead of cycle through them.
if (digitalRead(button1) == HIGH) // Beacons
{
if (BeaconStage == 2); // 1 SET ON , SO SWITCH OTHER OFF
{
digitalWrite(Relay5, HIGH);
BeaconStage = 0;
delay (1000);
}
if (BeaconStage == 1); // ALL ON , SO TURN OFF 1 RELAY
{
digitalWrite(Relay6, HIGH);
BeaconStage++;
delay (1000);
}
if (BeaconStage == 0); // NONE ON SO TURN ALL ON
{
digitalWrite(Relay5, LOW);
digitalWrite(Relay6, LOW);
BeaconStage++;
delay (1000);
}
};
any help with debounce as well as i have 3 other button for now that will only toggle
if (digitalRead(button1) == HIGH) // Beacons toggle
{
if (BeaconStage == 0) // NONE ON SO TURN ALL ON
{
digitalWrite(Relay5, LOW);
digitalWrite(Relay6, LOW);
BeaconStage++;
delay (1000);
};
if (BeaconStage == 2) // 1 SET ON , SO SWITCH OTHER OFF
{
digitalWrite(Relay5, HIGH);
BeaconStage = 0;
delay (1000);
};
if (BeaconStage == 1) // ALL ON , SO TURN OFF 1 RELAY
{
digitalWrite(Relay6, HIGH);
BeaconStage++;
delay (1000);
};
};
ok change but on first click both turn on then 1 turns off , break command work in ide ?
rest works ok
// Button toggle with extreme reliability!
const int led1Pin = 13; // LED pin number
const int button1 = 10;
int led1State = LOW; // initialise the LED
char bstate1 = 0;
unsigned long bcount1 = 0; // button debounce timer. Replicate as necessary.
// Have we completed the specified interval since last confirmed event?
// "marker" chooses which counter to check
// Routines by Paul__B of Arduino Forum
boolean timeout(unsigned long *marker, unsigned long interval) {
if (millis() - *marker >= interval) {
*marker += interval; // move on ready for next interval
return true;
}
else return false;
}
// Deal with a button read; true if button pressed and debounced is a new event
// Uses reading of button input, debounce store, state store and debounce interval.
// Routines by Paul__B of Arduino Forum
boolean butndown(char button, unsigned long *marker, char *butnstate, unsigned long interval) {
switch (*butnstate) { // Odd states if was pressed, >= 2 if debounce in progress
case 0: // Button up so far,
if (button == HIGH) return false; // Nothing happening!
else {
*butnstate = 2; // record that is now pressed
*marker = millis(); // note when was pressed
return false; // and move on
}
case 1: // Button down so far,
if (button == LOW) return false; // Nothing happening!
else {
*butnstate = 3; // record that is now released
*marker = millis(); // note when was released
return false; // and move on
}
case 2: // Button was up, now down.
if (button == HIGH) {
*butnstate = 0; // no, not debounced; revert the state
return false; // False alarm!
}
else {
if (millis() - *marker >= interval) {
*butnstate = 1; // jackpot! update the state
return true; // because we have the desired event!
}
else
return false; // not done yet; just move on
}
case 3: // Button was down, now up.
if (button == LOW) {
*butnstate = 1; // no, not debounced; revert the state
return false; // False alarm!
}
else {
if (millis() - *marker >= interval) {
*butnstate = 0; // Debounced; update the state
return false; // but it is not the event we want
}
else
return false; // not done yet; just move on
}
default: // Error; recover anyway
{
*butnstate = 0;
return false; // Definitely false!
}
}
}
void setup() {
pinMode(led1Pin, OUTPUT);
pinMode(button1, INPUT);
digitalWrite(button1,HIGH); // internal pullup all versions
}
void loop() {
// Toggle LED if button debounced
if (butndown(digitalRead(button1), &bcount1, &bstate1, 10UL )) {
if (led1State == LOW) {
led1State = HIGH;
}
else {
led1State = LOW;
}
digitalWrite(led1Pin, led1State);
}
}
That's a quite a few relays. Hope the Arduino isn't powering their coils directly or through a relay module. Hard to tell because I can't find your connection diagram or description.
dlloyd:
That's a quite a few relays. Hope the Arduino isn't powering their coils directly or through a relay module. Hard to tell because I can't find your connection diagram or description.
i got 12v to 5v mosfet , and 12v powerpack in testing , after got it working ill post final as wana put it all on a board
lcd screen dimmed when relays on so i know needs power