Created
June 30, 2015 22:33
-
-
Save wesalvaro/10411af41614c654c117 to your computer and use it in GitHub Desktop.
Read a Byte with ADK
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
#include <Max3421e.h> | |
#include <Usb.h> | |
#include <Max3421e_constants.h> | |
#include <AndroidAccessory.h> | |
AndroidAccessory acc("Google", | |
"Light Runner", | |
"LED Controller.", | |
"1.0", | |
"http://google.com", | |
"0000000000000001"); | |
#define LED3_RED 2 | |
#define LED3_GREEN 4 | |
#define LED3_BLUE 3 | |
#define LED2_RED 5 | |
#define LED2_GREEN 7 | |
#define LED2_BLUE 6 | |
#define LED1_RED 8 | |
#define LED1_GREEN 10 | |
#define LED1_BLUE 9 | |
void init_leds() | |
{ | |
digitalWrite(LED1_RED, 1); | |
digitalWrite(LED1_GREEN, 1); | |
digitalWrite(LED1_BLUE, 1); | |
pinMode(LED1_RED, OUTPUT); | |
pinMode(LED1_GREEN, OUTPUT); | |
pinMode(LED1_BLUE, OUTPUT); | |
digitalWrite(LED2_RED, 1); | |
digitalWrite(LED2_GREEN, 1); | |
digitalWrite(LED2_BLUE, 1); | |
pinMode(LED2_RED, OUTPUT); | |
pinMode(LED2_GREEN, OUTPUT); | |
pinMode(LED2_BLUE, OUTPUT); | |
digitalWrite(LED3_RED, 1); | |
digitalWrite(LED3_GREEN, 1); | |
digitalWrite(LED3_BLUE, 1); | |
pinMode(LED3_RED, OUTPUT); | |
pinMode(LED3_GREEN, OUTPUT); | |
pinMode(LED3_BLUE, OUTPUT); | |
} | |
void setup() { | |
init_leds(); | |
Serial.begin(115200); | |
acc.powerOn(); | |
} | |
#define NONE 0x0 | |
#define RIGHT 0x1 | |
#define LEFT 0x2 | |
void loop() | |
{ | |
if (acc.isConnected()) { | |
byte msg[1]; | |
int len = acc.read(msg, sizeof(msg), 1); | |
if (len > 0) { | |
byte b = msg[0]; | |
if (b == NONE) { | |
analogWrite(LED1_RED, 0); | |
analogWrite(LED2_RED, 0); | |
analogWrite(LED3_RED, 0); | |
} else if (b == RIGHT) { | |
analogWrite(LED1_RED, 255); | |
analogWrite(LED2_RED, 255); | |
analogWrite(LED3_RED, 0); | |
} else if (b == LEFT) { | |
analogWrite(LED3_RED, 255); | |
analogWrite(LED2_RED, 255); | |
analogWrite(LED1_RED, 0); | |
} else { | |
analogWrite(LED2_GREEN, 0); | |
} | |
} | |
analogWrite(LED2_GREEN, 0); | |
} else { | |
analogWrite(LED2_RED, 0); | |
analogWrite(LED2_GREEN, 255); | |
analogWrite(LED1_RED, 255); | |
analogWrite(LED3_RED, 255); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment