Mercurial > code > home > repos > homeauto
diff service/busyboxArduino/main.ino @ 962:70fd4c07a326
busybox py and arduino
Ignore-this: eea165c21e11600b5ac6787cbbb2239
darcs-hash:20150120020247-312f9-8977dd56e356d2752bc2cdf574aa37cef2036329
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Mon, 19 Jan 2015 18:02:47 -0800 |
parents | f83d494b0f31 |
children | 75b1dc5c0bdc |
line wrap: on
line diff
--- a/service/busyboxArduino/main.ino Mon Jan 19 18:02:27 2015 -0800 +++ b/service/busyboxArduino/main.ino Mon Jan 19 18:02:47 2015 -0800 @@ -1,8 +1,11 @@ #include <Arduino.h> #include <LiquidCrystal.h> +#include "DFR_Key.h" +#include "IRremote.h" +// see http://www.dfrobot.com/image/data/DFR0009/LCDKeypad%20Shield%20V1.0%20SCH.pdf #define I2C_ADDR 0x27 // I2C address of PCF8574A -#define BACKLIGHT_PIN 3 +#define BACKLIGHT_PIN 10 #define En_pin 9 #define Rw_pin 1 #define Rs_pin 8 @@ -11,41 +14,175 @@ #define D6_pin 6 #define D7_pin 7 -LiquidCrystal twilcd(Rs_pin, Rw_pin, En_pin, D4_pin, D5_pin, D6_pin, D7_pin, BACKLIGHT_PIN, POSITIVE); +LiquidCrystal lcd(Rs_pin, Rw_pin, En_pin, D4_pin, D5_pin, D6_pin, D7_pin, BACKLIGHT_PIN, POSITIVE); +DFR_Key keypad; #define debugLed 13 +byte backlightStandard = 0; +byte backlightCurrent = 0; +byte backlightKeypressBoost = 30; + +int lastKey = -1; +int lastUnsentKeydown = -1; +uint16_t steps = 0; +uint16_t stepDelayPerBrightnessFade = 2048; + +IRsend irsend; + +void sendnec(byte addr, byte cmd) { + uint32_t w = 0x00ff0000; + w |= (cmd << 8) & 0xff00; + w |= (~cmd) & 0xff; + irsend.sendNEC(w, 32); + delay(100); +} void setup(void) { - int i; pinMode(debugLed, OUTPUT); - Serial.begin(115200); - - twilcd.begin(16,2); - twilcd.setBacklight(HIGH); - twilcd.home(); - //1234567890123456 - //I2C/TWI BackPack - twilcd.print("hello world"); - // ana read and display - while (1) { - while (Serial.available() <= 2) { - } - i = Serial.read(); - if (i != 0x60) { - continue; - } - i = Serial.read(); // command - if (i == 0) { // set strip: 0x60 0x00 <numPixels * 3 bytes> - digitalWrite(debugLed, 1); - delay(1000); - digitalWrite(debugLed, 0); - } else { - // unknown command - } + keypad.setRate(10); + lcd.begin(16,2); + + + for (int i = 0; i < 1; i++) { + digitalWrite(debugLed,1); + /* +44 key remote. command chart: http://blog.allgaiershops.com/2012/05/ +Up Down Play Pwr +0x3A 0xBA 0x82 0x02 + +Red Grn Blu Wht +1A 9A A2 22 + +2A AA 92 12 + +0A 8A B2 32 + +38 B8 78 F8 + +18 98 58 D8 + +RUp GUp BUp Quick +28 A8 68 E8 + +RDn GDn BDn Slow +08 88 48 C8 + +DIY1 DIY2 DIY3 AUTO +30 B0 70 F0 + +DIY4 DIY5 DIY6 Flash +10 90 50 D0 + +JMP3 JMP7 Fade Fade7 +20 A0 60 E0 + + irsend.sendNEC(0xff0002fd, 32); + irsend.sendNEC(0x00ff02fd, 32); + irsend.sendNEC(0x00ff40bf, 32); + irsend.sendNEC(0xff0040bf, 32); + */ + delay(100); + + // LED618 remote command byte (addr is ff) + // see https://github.com/alistairallan/RgbIrLed/blob/master/RgbIrLed.cpp#L44 +#define ON 0xE0 +#define OFF 0x60 +#define BRIGHTNESS_UP 0xA0 +#define BRIGHTNESS_DOWN 0x20 +#define FLASH 0xF0 +#define STROBE 0xE8 +#define FADE 0xD8 +#define SMOOTH 0xC8 + +#define RED 0x90 +#define GREEN 0x10 +#define BLUE 0x50 +#define WHITE 0xD0 + +#define ORANGE 0xB0 +#define YELLOW_DARK 0xA8 +#define YELLOW_MEDIUM 0x98 +#define YELLOW_LIGHT 0x88 + +#define GREEN_LIGHT 0x30 +#define GREEN_BLUE1 0x28 +#define GREEN_BLUE2 0x18 +#define GREEN_BLUE3 0x08 + +#define BLUE_RED 0x70 +#define PURPLE_DARK 0x68 +#define PURPLE_LIGHT 0x58 +#define PINK 0x48 + sendnec(0xff, ON); + + digitalWrite(debugLed,0); + delay(100); } } + void loop() { + while (Serial.available() <= 2) { + int localKey = keypad.getKey(); + if (localKey != SAMPLE_WAIT) { + if (localKey != lastKey) { + if (lastKey == 0) { + backlightCurrent = min(255, backlightStandard + + backlightKeypressBoost); + lastUnsentKeydown = localKey; + } + lastKey = localKey; + } + } + + if (backlightCurrent > backlightStandard) { + steps++; + if (steps % stepDelayPerBrightnessFade == 0) { + backlightCurrent--; + } + } else if (backlightCurrent < backlightStandard) { + backlightCurrent = backlightStandard; + } + lcd.setBacklight(backlightCurrent); + } + byte i = Serial.read(); + if (i != 0x60) { + return; + } + i = Serial.read(); // command + if (i == 0) { // get status + Serial.print('{'); + if (lastUnsentKeydown != -1) { + Serial.print("\"keyDown\":"); + Serial.print(lastUnsentKeydown); + Serial.print(","); + lastUnsentKeydown = -1; + } + Serial.print("\"slider1\":"); Serial.print(analogRead(1)); + Serial.print(",\"slider2\":"); Serial.print(analogRead(2)); + Serial.print(",\"slider3\":"); Serial.print(analogRead(3)); + Serial.print(",\"slider4\":"); Serial.print(analogRead(4)); + Serial.print("}\n"); + } else if (i == 1) { // write text + while (Serial.available() < 3) NULL; + byte row = Serial.read(); + byte col = Serial.read(); + byte nchars = Serial.read(); + char buf[32]; + char *p=buf; + while (nchars--) { + while (Serial.available() < 1) NULL; + *(p++) = Serial.read(); + } + *p = 0; + lcd.setCursor(row, col); + lcd.print(buf); + } else if (i == 2) { // set backlight + while (Serial.available() < 1) NULL; + backlightStandard = Serial.read(); + } else { + // unknown command + } }