Understanding a code
hello, im complete lake if comes arduino. however, have managed build awesome projects far.
oke found code on internet controlling youre arduino via bluetooth. basic idea hook op ho-06 bluetooth module arduino , send information via app on phone. however, not understand how code works. can edit use other trigger words or make performe different action, want make recive variable value arduino can use dimm led. (as start project) cant figure how that.
(btw, sorry bad englisch, im netherlands)
here code, , youtube video of original project:
please explain it?
//http://www.youtube.com/user/greatscottlab
moderator edit: usual.
oke found code on internet controlling youre arduino via bluetooth. basic idea hook op ho-06 bluetooth module arduino , send information via app on phone. however, not understand how code works. can edit use other trigger words or make performe different action, want make recive variable value arduino can use dimm led. (as start project) cant figure how that.
(btw, sorry bad englisch, im netherlands)
here code, , youtube video of original project:
please explain it?
//http://www.youtube.com/user/greatscottlab
code: [select]
int ledred=8;
int ledgreen=9;
int ledblue=10;
int tx=1;
int rx=0;
char inserial[15];
void setup(){
serial.begin(9600);
pinmode(ledred, output);
pinmode(ledgreen, output);
pinmode(ledblue, output);
pinmode(tx, output);
pinmode(rx, input);
allpinslow();
}
void loop(){
int i=0;
int m=0;
delay(500);
if (serial.available() > 0) {
while (serial.available() > 0) {
inserial[i]=serial.read();
i++;
}
inserial[i]='\0';
check_protocol(inserial);
}}
void allpinslow()
{
digitalwrite(ledred, high);
digitalwrite(ledgreen, high);
digitalwrite(ledblue, high);
}
void check_protocol(char instr[]){
int i=0;
int m=0;
serial.println(instr);
if(!strcmp(instr,"red")){ //ledred on
allpinslow();
digitalwrite(ledred, low);
serial.println("red on");
for(m=0;m<11;m++){
instr[m]=0;}
i=0;}
if(!strcmp(instr,"green")){ //ledgreen on
allpinslow();
digitalwrite(ledgreen, low);
serial.println("green on");
for(m=0;m<11;m++){
instr[m]=0;}
i=0;}
if(!strcmp(instr,"blue")){ //ledblue on
allpinslow();
digitalwrite(ledblue, low);
serial.println("blue on");
for(m=0;m<11;m++){
instr[m]=0;}
i=0;}
else{
for(m=0;m<11;m++){
instr[m]=0;
}
i=0;
}}
moderator edit: usual.
you need extend accept more complicated message - you'd need put in delimiter, , use strtok() separate command numeric parameter, , atoi() convert parameter integer.
take @ serial input basics
take @ serial input basics
Arduino Forum > Using Arduino > Programming Questions > Understanding a code
arduino
Comments
Post a Comment