153
|
1 #include <Arduino.h>
|
|
2 #include <LiquidCrystal.h>
|
|
3
|
|
4 #define I2C_ADDR 0x27 // I2C address of PCF8574A
|
|
5 #define BACKLIGHT_PIN 3
|
|
6 #define En_pin 9
|
|
7 #define Rw_pin 1
|
|
8 #define Rs_pin 8
|
|
9 #define D4_pin 4
|
|
10 #define D5_pin 5
|
|
11 #define D6_pin 6
|
|
12 #define D7_pin 7
|
|
13
|
|
14 LiquidCrystal twilcd(Rs_pin, Rw_pin, En_pin, D4_pin, D5_pin, D6_pin, D7_pin, BACKLIGHT_PIN, POSITIVE);
|
|
15
|
|
16 #define debugLed 13
|
|
17
|
|
18
|
|
19 void setup(void) {
|
|
20 int i;
|
|
21 pinMode(debugLed, OUTPUT);
|
|
22
|
|
23 Serial.begin(115200);
|
|
24
|
|
25 twilcd.begin(16,2);
|
|
26 twilcd.setBacklight(HIGH);
|
|
27 twilcd.home();
|
|
28 //1234567890123456
|
|
29 //I2C/TWI BackPack
|
|
30 twilcd.print("hello world");
|
|
31 // ana read and display
|
|
32 while (1) {
|
|
33 while (Serial.available() <= 2) {
|
|
34 }
|
|
35 i = Serial.read();
|
|
36 if (i != 0x60) {
|
|
37 continue;
|
|
38 }
|
|
39 i = Serial.read(); // command
|
|
40 if (i == 0) { // set strip: 0x60 0x00 <numPixels * 3 bytes>
|
|
41 digitalWrite(debugLed, 1);
|
|
42 delay(1000);
|
|
43 digitalWrite(debugLed, 0);
|
|
44 } else {
|
|
45 // unknown command
|
|
46 }
|
|
47 }
|
|
48 }
|
|
49
|
|
50 void loop() {
|
|
51 }
|