[175] | 1 | /*
|
---|
| 2 | Simple GPIO
|
---|
| 3 |
|
---|
| 4 | A simple Arduino sketch that turn off and on the onboard relais and leds of the Lucky Shield.
|
---|
| 5 | When the joystick is moved on the left, led n1 and relay n1 are turned on,
|
---|
| 6 | when the joystick is moved on the right, led n2 and relay n2 are turned off.
|
---|
| 7 |
|
---|
| 8 | The following pins are defined in the Lucky Shield library, they directly map the digitals
|
---|
| 9 | of the Lucky Shield
|
---|
| 10 |
|
---|
| 11 | LED1: on board first LED
|
---|
| 12 | LED2: on board second LED
|
---|
| 13 |
|
---|
| 14 | REL1: on board first Relay
|
---|
| 15 | REL2: on board second Relay
|
---|
| 16 |
|
---|
| 17 | JOYR: on board Joystick - moved right
|
---|
| 18 | JOYL: on board Joystick - moved left
|
---|
| 19 | JOYU: on board Joystick - moved up
|
---|
| 20 | JOYD: on board Joystick - moved down
|
---|
| 21 | JOYC: on board Joystick - central pressed
|
---|
| 22 |
|
---|
| 23 | PIR: on board (Passive Infrared Sensor) Presence Sensor
|
---|
| 24 |
|
---|
| 25 | PB1: on board first Push Button
|
---|
| 26 | PB2: on board second Push Button
|
---|
| 27 |
|
---|
| 28 | created Mar 2016
|
---|
| 29 | by andrea@arduino.org,
|
---|
| 30 | sergio@arduino.org
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | #include <Lucky.h>
|
---|
| 34 | #include <Wire.h>
|
---|
| 35 |
|
---|
| 36 | void setup() {
|
---|
| 37 | lucky.begin();
|
---|
| 38 |
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | void loop() {
|
---|
| 42 |
|
---|
| 43 | //Check if the the joystick is moved to the left
|
---|
| 44 | if(lucky.gpio().digitalRead(JOYL) == HIGH){
|
---|
| 45 | lucky.gpio().digitalWrite(LED1, HIGH);
|
---|
| 46 | lucky.gpio().digitalWrite(REL1, HIGH);
|
---|
| 47 | }
|
---|
| 48 | else {
|
---|
| 49 | lucky.gpio().digitalWrite(LED1, LOW);
|
---|
| 50 | lucky.gpio().digitalWrite(REL1, LOW);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | //Check if the the joystick is moved to the right
|
---|
| 54 | if(lucky.gpio().digitalRead(JOYR) == HIGH){
|
---|
| 55 | lucky.gpio().digitalWrite(LED2, HIGH);
|
---|
| 56 | lucky.gpio().digitalWrite(REL2, HIGH);
|
---|
| 57 | }
|
---|
| 58 | else {
|
---|
| 59 | lucky.gpio().digitalWrite(LED2, LOW);
|
---|
| 60 | lucky.gpio().digitalWrite(REL2, LOW);
|
---|
| 61 | }
|
---|
| 62 | }
|
---|