Created
February 21, 2015 20:48
-
-
Save raimohanska/da867e604df59d193b91 to your computer and use it in GitHub Desktop.
Arduino enocean dimmer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int SIGNAL_LED = 13; | |
int POWER_LED = 11; | |
byte buffer[100]; | |
byte myAddress[] = {-1, -114, 70, -125}; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(SIGNAL_LED, OUTPUT); | |
pinMode(POWER_LED, OUTPUT); | |
} | |
void loop() { | |
if (Serial.available() > 3) { | |
int sync1 = Serial.read(); | |
int sync0 = Serial.read(); | |
if (sync1 == 165 && sync0 == 90) { | |
int length = Serial.read() & 31; | |
byte result = Serial.readBytes((char*)buffer, length); | |
if (result >= length) { | |
if (isForMe()) { | |
setBrightness(buffer[2]); | |
} | |
} | |
} | |
} | |
} | |
void setBrightness(int brightnessIn) { | |
Serial.print("Brightness "); | |
Serial.println(brightnessIn); | |
int powerLedBrightness = map(brightnessIn, 0, 100, 0, 255); | |
analogWrite(POWER_LED, powerLedBrightness); | |
blink(); | |
} | |
void blink() { | |
digitalWrite(SIGNAL_LED, HIGH); | |
delay(100); | |
digitalWrite(SIGNAL_LED, LOW); | |
} | |
int isForMe() { | |
for (int i = 0; i < 4; i++) { | |
if (myAddress[i] != buffer[i + 5]) return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use Enocean TCM320 to receive enocean packets. Connection:
Arduino pin 11 is used to dim your LEDs using PWM. Enjoy!