Comparing strings & output


hi all, have been trying send signal arduino, "l1, l2...", , in return change output of pin 3 digital pot mcp4131.
right now, code isn't able output anything, can take look?
--also, if need output half voltage "l2", how that?
thank you. here's code far:


#include <spi.h>
#define degrees0    3

char l1=0;
char l2=0;
char l3=0;

void setup() {
  serial.begin(9600); //begin serial communication
  pinmode(degrees0, output); //send output pin 3 on uno
  digitalwrite(degrees0, low); //set initial output zero/spi.transfer(0)
}

void loop() { 
    if(serial.available()){
        int ind=0;
        char buff[5];
        while(serial.available()){
            unsigned char c = serial.read();
            buff[ind] = c;
            if(ind++ > 6) break;
        }
        buff[2]=0;
        if(strcmp(buff, "l1")==0){  //if off button clicked
            serial.println("0 volts");
            //spi.transfer(0);
            digitalwrite(degrees0, low);
          }
        if(strcmp(buff, "l2")==0){ //if 2.5v button clicked
            serial.println("2.5 volts");
            //spi.transfer(64);
            //digitalwrite(degrees0, 64);
          }   
        if(strcmp(buff, "l3")==0){ //if 5.0v button clicked
            serial.println("5.0 volts");
            //spi.transfer(128);
            digitalwrite (degrees0, high);
          }       
     }
}

code: [select]
        while(serial.available()){
            unsigned char c = serial.read();
            buff[ind] = c;
            if(ind++ > 6) break;
        }
post code in code tags. above code assumes whole string available in 1 go. never true.

mark


Arduino Forum > Using Arduino > Project Guidance > Comparing strings & output


arduino

Comments