How To: Make a Simple/Cheap Scene Controller (with video)
My Project
62
Posts
19
Posters
40.1k
Views
15
Watching
-
Hello,
Here an update of the original sketch with a small modif to add a buzzer for validating the keypress.
It will beep once for short key press and twice for the long one.
The buzzer is connected on D3 and the beep length can be adjusted in the function.
Your feedback and improvement ideas are welcome.
Best regards,
Jef
#define MY_DEBUG #define MY_RADIO_NRF24 // Set LOW transmit power level as default, if you have an amplified NRF-module and // power your radio separately with a good regulator you can turn up PA level. /* - RF24_PA_MIN = -18dBm * - RF24_PA_LOW = -12dBm * - RF24_PA_HIGH = -6dBm * - RF24_PA_MAX = 0dBm */ #define MY_RF24_PA_LEVEL RF24_PA_HIGH // Enabled repeater feature for this node #define MY_REPEATER_FEATURE // activate signal report // #define MY_SIGNAL_REPORT_ENABLED #include <SPI.h> #include <MySensors.h> #include <Keypad.h> #define NODE_ID AUTO // or set to AUTO if you want gw to assign a node id for you. #define SN "Keypad Scene Controller" #define SV "2.1" #define KEYPAD_CHILD_ID 95 MyMessage scene(KEYPAD_CHILD_ID, V_SCENE_ON); //scene ON MyMessage scene2(KEYPAD_CHILD_ID, V_SCENE_OFF); //scene OFF int buzzer = 3; // buzzer pin const byte ROWS = 4; //four rows const byte COLS = 1; //one column char keys[ROWS][COLS] = { {'1'}, {'2'}, {'3'}, {'4'} }; byte rowPins[ROWS] = {6, 7, 4, 5}; //connect to the row pinouts of the keypad byte colPins[COLS] = {8}; //connect to the column pinouts of the keypad Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); byte lastState; void setup() { sendSketchInfo(SN, SV); present(KEYPAD_CHILD_ID, S_SCENE_CONTROLLER); keypad.addEventListener(keypadEvent); pinMode(buzzer, OUTPUT); } /* * Declare the buzzer function. * Adjust the delay to fit your preferences */ void beep() { digitalWrite(buzzer, HIGH); delay(50); digitalWrite(buzzer, LOW); } void loop() { char key = keypad.getKey(); } void keypadEvent(KeypadEvent key) { switch (keypad.getState()) { case PRESSED: lastState = 1; beep(); break; case HOLD: lastState = 2; beep(); break; case RELEASED: int keyInt = key - '0'; //Quick way to convert Char to Int so it can be sent to controller if (lastState == 2) { //keyInt = keyInt + 4; //If button is held, add 4. If using more than 4 buttons this number will need to be changed send(scene2.set(keyInt)); } else { send(scene.set(keyInt)); } //break; } } -
I want to use this mysensors touch sensor to adjust a selector switch in domoticz, so if I select scene 1 the selector switch in Domoticz goes to 10%, and scene 2 to 20% and so on. Is that possible and how do I do that?