Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eeaslan/5e5373b4710bbc34e03c to your computer and use it in GitHub Desktop.
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.
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);}
}
}
}
@mtokeyboard
Copy link

Hey it works fine.
Thank you...

-a noob arduino hobbyist enjoying your code :-)

@asus246
Copy link

asus246 commented Nov 27, 2018

moge dostac

@saidsadiek
Copy link

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment