Created
January 22, 2013 14:49
-
-
Save YuuichiAkagawa/4595181 to your computer and use it in GitHub Desktop.
HelloADK sketch for RLduino78
This file contains hidden or 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
| /* | |
| * HelloADK | |
| * Android ADK(AOA1.0) sample sketch for RLduino78 | |
| * Copyright (C) 2013 Yuuichi Akagawa | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| #include <RLduino78.h> | |
| #include <Max3421e.h> | |
| #include <Usb.h> | |
| #include <AndroidAccessory.h> | |
| #define LED1 3 | |
| #define BUTTON1 4 | |
| int led_red = 22; | |
| int led_green = 23; | |
| int led_blue = 24; | |
| AndroidAccessory acc("ammlab.org", | |
| "HelloADK", | |
| "HelloADK for Arduino", | |
| "1.0", | |
| "https://play.google.com/store/apps/details?id=org.ammlab.android.helloadk", | |
| "0000000012345678"); | |
| byte oldval = 0; | |
| void setup() | |
| { | |
| // Serial.begin(115200); | |
| pinMode(LED1, OUTPUT); | |
| pinMode(BUTTON1, INPUT_PULLUP); | |
| acc.powerOn(); | |
| } | |
| void loop() | |
| { | |
| byte msg[64]; | |
| byte val = 0; | |
| if (acc.isConnected()) { | |
| int len = acc.read(msg, sizeof(msg), 1); | |
| if (len > 0) { | |
| // Serial.print(len); | |
| // Serial.println(" bytes received."); | |
| if (msg[0] == 0x1) { | |
| if( msg[1] == 0x01){ | |
| digitalWrite(LED1, HIGH); | |
| } else { | |
| digitalWrite(LED1, LOW); | |
| } | |
| } | |
| if(msg[0] == 0x02) { | |
| if( msg[1] != 0){ | |
| digitalWrite(LED1, 0); | |
| analogWrite(LED1, msg[1]); | |
| } | |
| } | |
| } | |
| val = digitalRead(BUTTON1); | |
| if( val != oldval ){ | |
| msg[0] = 0x1; | |
| if( val == 0 ){ | |
| msg[1] = 0x1; | |
| }else{ | |
| msg[1] = 0x0; | |
| } | |
| acc.write(msg, 2); | |
| oldval = val; | |
| } | |
| } else { | |
| analogWrite(LED1, LOW); | |
| } | |
| delay(10); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment