Created
May 6, 2014 06:08
-
-
Save eeaslan/5e5373b4710bbc34e03c to your computer and use it in GitHub Desktop.
This software is the Arduino Uno firmware of a project called "Arduino Uno Port Control". The aim of this project is to control the digital I/O pins of Arduino Uno from an Android device. The android app can be downloaded from Google Play Store.
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
byte lineEnding = 0x0A; | |
//Data array that the received info from android app is recorded. Every byte corresponds to a digital pin. | |
byte readBuffer[15]; //For example readBuffer[5] is for digital pin 5. | |
byte defaultByte = 0x10; //On start all arduino digital pins must be input for electrical protection. | |
//Pins 0 and 1 are used for serial comminations. So read | |
void setup() { | |
for (int i=0; i < sizeof(readBuffer)-1 ; ++i) { | |
readBuffer[i] = defaultByte;} | |
Serial.begin(9600); | |
} | |
void loop() { | |
if (Serial.available() > 14) { | |
Serial.readBytesUntil(lineEnding, (char*) readBuffer, 15); | |
for (int i=2; i < sizeof(readBuffer)-1 ; i++ ) { | |
if( bitRead(readBuffer[i], 4 )) { pinMode(i,INPUT);} else { pinMode(i,OUTPUT);} | |
} | |
for (int i=2; i < sizeof(readBuffer)-1 ; i++ ) { | |
if( bitRead(readBuffer[i], 0 )) { digitalWrite(i,HIGH);} else { digitalWrite(i,LOW);} | |
} | |
} | |
} | |
moge dostac
Thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey it works fine.
Thank you...
-a noob arduino hobbyist enjoying your code :-)