Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
21 | jlesech | 1 | /* |
2 | * Snootlab Deuligne joystick testing demo |
||
3 | * Initial code from nuelectronics |
||
4 | * |
||
5 | * copyleft 2011 snootlab |
||
6 | * free software, have fun ! |
||
7 | * |
||
8 | */ |
||
9 | |||
10 | #include <Wire.h> // I2C library include |
||
11 | #include <Deuligne.h> // LCD library include |
||
12 | |||
13 | Deuligne lcd; // lcd object declaration |
||
14 | |||
15 | //Key message |
||
16 | char msgs[5][15] = { |
||
17 | "Right Key OK ", |
||
18 | "Up Key OK ", |
||
19 | "Down Key OK ", |
||
20 | "Left Key OK ", |
||
21 | "Select Key OK" }; |
||
22 | int key=-1; |
||
23 | int oldkey=-1; |
||
24 | |||
25 | |||
26 | void setup() |
||
27 | { |
||
28 | Wire.begin(); // join i2c |
||
29 | lcd.init(); // LCD init |
||
30 | |||
31 | lcd.clear(); // Clear Display |
||
32 | |||
33 | lcd.backLight(true); // Backlight ON |
||
34 | |||
35 | lcd.setCursor(5,0); // Place cursor row 6, 1st line (counting from 0) |
||
36 | lcd.print("Setup"); |
||
37 | lcd.setCursor(7,1); // Place cursor row 8, 2nd line (counting from 0) |
||
38 | lcd.print("ok"); |
||
39 | delay(2000); |
||
40 | lcd.clear(); |
||
41 | lcd.print("Move Joystick"); |
||
42 | } |
||
43 | |||
44 | void loop() { |
||
45 | |||
46 | |||
47 | key = lcd.get_key(); // read the value from the sensor & convert into key press |
||
48 | |||
49 | if (key != oldkey) // if keypress is detected |
||
50 | { |
||
51 | delay(50); // wait for debounce time |
||
52 | key = lcd.get_key(); // read the value from the sensor & convert into key press |
||
53 | if (key != oldkey) |
||
54 | { |
||
55 | oldkey = key; |
||
56 | if (key >=0){ |
||
57 | // set the cursor to column 0, line 1 |
||
58 | // (note: line 1 is the second row, since counting begins with 0): |
||
59 | lcd.setCursor(0, 1); |
||
60 | // print the key pressed: |
||
61 | lcd.print(msgs[key]); |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 | |||
66 | //delay(1000); |
||
67 | } |
||
68 |