In the end it doesn't make much difference to the code, because the compiler is doing the needed type conversions in the Serial.read and switch statement, but you will see a difference in a Serial.print, where a byte will print as a number, and a char as an ascii character, so having the name implying a different type than it actually is can lead to confusion. gearbox1 is value read from Nextion screen gearbox1myNextion.getComponentValue('G1') What i am trying to achieve is, when case 10 (witch is checked once a second) run a 10 second loop turning output on and off. Im using a push button to switch between 6 LED lights (modes) and within that modes i want to add another push button that when it is pressed theres 2 lights turning on and off with diff. ![]() For a char, inChar would be a more suitable name. I want to put a conditional statement inside a case command that is in a loop (because i think the break command is preventing it). If you had only declared inByte once, where you did the Serial.read within the if statement, all of your references to inByte outside of the if statement would have been out of scope, because inByte would no longer exist once you leave the section it was defined in.Īs for the other comments you have gotten, if I were going to call the variable inByte, I would have defined it as a byte. Can anybody please help me solve this problem ? void loop(). Like if statements, switch case controls the flow of programs by allowing programmers to specify different code that should be executed in various conditions. In particular, a switch statement compares the value of a variable to the values specified in case statements. I have tried everything and searched everywhere but couldn't find a solution. switch.case Description Like if statements, switch case controls the flow of programs by allowing programmers to specify different code that should be executed in various conditions. I need the code to keep looping until for example i choose switch case 's' to stop the car. ![]() ![]() The problem is when i use switch case 'a', the code runs once and stops. In Arduino programming the switch case statements are also used to regulate the flow of the code using conditional statements. So i have made a small autonomous car and what i'm trying to do now is to control it by switch case.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |