Hi
Need your help to check what is wrong with our sketch below. We are currently doing a project wherein we will control the selection of pattern and operation of our ovens using arduino board. My problem is, I can't display patterns 10 and above. And also, please check if my sketch is correct on the last portion wherein '0' data will be read by tool as '1' and vise versa. Our oven has reverse interpretation on arduino signals that is why we added that portion on the sketch.
Here is how our project works
Oven has different recipe patterns (1, 2, 3,4 etc) - if arduino reads '1' oven will display '01' on its controller etc etc
If arduino reads 's' - oven will automatically turned ON
Attached here is our LED diagram which represents the pattern number and start operation.
Below is our sketch.
String input = "";
void setup(){
Serial.begin(9600); // Sets up communication with the serial port
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT); // for start of program operation
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
void loop(){
int recipe;
//Serial.print("Enter recipe number: ");
while(Serial.available()==0){ // Waits for data from serial port
}
while(Serial.available() > 0){
int data = Serial.read();
// convert the incoming byte to a char
// and add it to the string
input += (char)data;
recipe = input.toInt()+'0'; //recipe=0 if not a digit
if(recipe == '0')
recipe = data;
if(data == '\n'){
//Serial.print("Recipe: ");
//Serial.println(recipe);
//Serial.print("String: ");
//Serial.println(input);
input = "";
}
}
if(recipe == 's'){
digitalWrite(11,HIGH);
delay(1000);
digitalWrite(11,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
}
else if(recipe>'0' && recipe<'32'){
recipe = recipe-'0';
char binary[7] = {0}; // This is where the binary representation will be stored
recipe += 32; // Adding 32 so that there will always be 6 digits in the string
itoa(recipe,binary,2); // Convert recipe to a string of base 2 and save it in array 'binary'
char* signals = binary + 1; // Get rid of the most significant digit to get the 5 bits
//Serial.print(signals); // Print out the signals in binary
int i;
for(i=0; i<5; i++){
if(signals[i] == '0')
signals[i] = '1';
else
signals[i] = '0';
digitalWrite(i+6, signals[i]-'0'); // write to pin; converts the bit of the string to HIGH or LOW
//Serial.print(signals[i]);
}
}
}
