126: speedTrainA = speedArrayA break Īnd you write a small formula that gives you 23 if the switch value is 103 and 0 if the switch value is 126. You can use the range notation and do a bit of maths case 103. Note as well that instead of writing tons of similar cases like you did case 103: speedTrainA = speedArrayA break Put the printing before or after the switch. So whatever you put outside the labels is not of much use. The break statement, when encountered in statement exits the switch statement If condition evaluates to the value that doesn't match any of the case: labels, and the default: label is present, control is transferred to the statement labeled with the default: label. If condition evaluates to the value that is equal to the value of one of constant_expressions, then control is transferred to the statement that is labeled with that constant_expression. in between if I press PushButton1 for 2 seconds the Arduino must enter into programming mode. What does the doc about switch case say the compiler will do upon entering the switch or finding break PROJECT OUTLINE: There are 3 sensors (Temp., Accelerometer & Humidity) will read the respective parameters continuously. Wire.write(dataToI2C) // respond with message to master SENSOR_A1_Trigger = digitalRead(SENSOR_A1 ) If (dataFromI2C != 0) Serial.println(dataFromI2C) Ĭase 103: speedTrainA = speedArrayA break Ĭase 104: speedTrainA = speedArrayA break Ĭase 105: speedTrainA = speedArrayA break Ĭase 106: speedTrainA = speedArrayA break Ĭase 107: speedTrainA = speedArrayA break Ĭase 108: speedTrainA = speedArrayA break Ĭase 109: speedTrainA = speedArrayA break Ĭase 110: speedTrainA = speedArrayA break Ĭase 111: speedTrainA = speedArrayA break Ĭase 112: speedTrainA = speedArrayA break Ĭase 113: speedTrainA = speedArrayA break Ĭase 114: speedTrainA = speedArrayA break Ĭase 115: speedTrainA = speedArrayA break Ĭase 116: speedTrainA = speedArrayA break Ĭase 117: speedTrainA = speedArrayA break Ĭase 118: speedTrainA = speedArrayA break Ĭase 119: speedTrainA = speedArrayA break Ĭase 120: speedTrainA = speedArrayA break Ĭase 121: speedTrainA = speedArrayA break Ĭase 122: speedTrainA = speedArrayA break Ĭase 123: speedTrainA = speedArrayA break Ĭase 124: speedTrainA = speedArrayA break Ĭase 125: speedTrainA = speedArrayA break Ĭase 126: speedTrainA = speedArrayA break I feel like there is a basic error I'm making, but I cant see it. The slave receives data (106, 107, 108, etc) and my switch statement should convert it into a number from the array (140, 130, 120) which is the speed of the motor, but for some reason doesnt. The slave is receiving the data correctly but it is ignoring my attempt to turn the case into an array value (the speed of the motor). I wish to use the data received in a switch/ case statement, and for some reason, I cant get it to work. I have my master sending the pot data correctly to the slave. I have a project where I want to control a motordriver with a potentiometer over i2C.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |