/*
Scope and purpose:
en power on knapp som styre ingangsrele te 24v rail
en Loudness knapp som styre et rele som skrur 2 tweetera på
en toggle switch som e på et aent kort men når den e High 3.3v så ska an skru av et rele og på et anna og motsatt
må tenka energieffektivt her og
kan ikkje ha masse rele så trekke strøm når du e på batteri
*/
// Preprocessor stuff
// Libraries
#include <Arduino.h>
#include <OneButton.h> // Easy to use library for buttons: https://github.com/mathertel/OneButton
// Pin definitions
// Button pins
#define BTN_PIN_8 8
#define BTN_PIN_9 9
#define BTN_PIN_10 10
// Output pins
#define PWR_24V_PIN 7
#define TWEETERS_PIN 6
#define EXT_TOGGLESW_PIN 5
// Objects creation
// Button object = OneButton(pin#, active low?, internal pullup?);
OneButton btn1 = OneButton(BTN_PIN_8, true, true); // Blue
OneButton btn2 = OneButton(BTN_PIN_9, true, true); // Green
OneButton btn3 = OneButton(BTN_PIN_10, true, true); // Red
void setup() {
// Initialize pins
// Inputs/buttons
pinMode(BTN_PIN_8, INPUT_PULLUP); // Blue
pinMode(BTN_PIN_9, INPUT_PULLUP); // Green
pinMode(BTN_PIN_10, INPUT_PULLUP); // Red
// Outputs
pinMode(PWR_24V_PIN, OUTPUT); // Pin 7, Blue
pinMode(TWEETERS_PIN, OUTPUT); // Pin 6, Green
pinMode(EXT_TOGGLESW_PIN, OUTPUT); // Pin 5, Red
// Config objects
btn1.attachClick(onClick1); // Fires as soon as a single click is detected
btn1.attachLongPressStart(longPress1); // Fires as soon as the button is held down for 1 second
btn2.attachClick(onClick2); // Fires as soon as a single click is detected
btn2.attachLongPressStart(longPress2); // Fires as soon as the button is held down for 1 second
btn3.attachClick(onClick3); // Fires as soon as a single click is detected
btn3.attachLongPressStart(longPress3); // Fires as soon as the button is held down for 1 second
}
void onClick1() {
digitalWrite(PWR_24V_PIN, HIGH);
}
void longPress1() {
digitalWrite(PWR_24V_PIN, LOW);
}
void onClick2() {
digitalWrite(TWEETERS_PIN, HIGH);
}
void longPress2() {
digitalWrite(TWEETERS_PIN, LOW);
}
void onClick3() {
digitalWrite(EXT_TOGGLESW_PIN, HIGH);
}
void longPress3() {
digitalWrite(EXT_TOGGLESW_PIN, LOW);
}
void loop() {
btn1.tick();
btn2.tick();
btn3.tick();
}