8/16/2023 0 Comments Mcwhorter arduino while loop![]() While(Serial.available()=0)//WHILE serial. Serial.println(msg1) //Ask for input from user/sensor While(Serial.available())//start a loop to print in "question" string Is that what you're getting Your question is incomplete. I would expect this code to print: either 'inside while loop' (if pin 2 is false) or nothing, followed by 'Break.' over and over again. THIS PRINTS THE "msg1" String 1 time each loop then breaks 1 The while (1) loop executes once, every time loop () is called, printing or not, depending on the state of pin2. Serial.println(msg1) //print out initial "string" aka msg1 Serial.begin(9600) //intialize serial com at 9600 baud Int number //assign "number" for variable value later ![]() Referencing post #7 ^^^^ if i rewrite the same code as this then it prints perfectly with no double printing: again i'm just trying to understand why his codes are not working on my unit when i'm plain as day copying his code letter for letter It enters in 1 count command and then offers no more input commandsĪs per the serial.available syntax page and now it just infinitely loops the question without waiting for an input. While(Serial.available())//WHILE serial.avail do nothing and wait ![]() I'm not a master programmer or anything but i've played with c++ for a few years before compilers could be downloaded onto phones and MSDOS and shell systems were "the up and coming thing". Why is it printing : Serial.println(question) at the beginning twice? I'm making sure i don't have a bug in my atmel328 pic. 'Serial.read () is not blocking, it always returns immediately with a byte 0-255 or -1 if there is no character to read.' unless it returns a multi-byte data type, it couldn't return 0-255 or -1 -> as -1 is 128. WHY? IT has nothing to do with my serial.available if my Rewritten code functioned using it. If you can avoid filling up the buffer you will be okay. ![]() When i use his exact code letter for letter i have a double print. THEN SHOWS SAID CODE FUNCTIONING IN THE SAME VIDEO IN VIDEO.Īrduino Tutorial 18: Reading Numbers from the Serial Monitor | Technology Tutorials () THERE ARE NO ERRORS IN HIS CODE IF IT'S WORKING IN HIS VIDEO! I'VE COPIED IT LETTER FOR LETTER IN THE VIDEO! HE LITTERALLY ZOOMS IN ON THE CODE FOR YOU TO COPY IT ALONG WITH HIM. Something must change the tested variable, or the while loop will never exit. A while loop will loop continuously, and infinitely, until the expression inside the parenthesis, becomes false. HIS EXACT CODE ON MY SYSTEM PRODUCES A DOUBLE PRINT! The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords. HIS VIDEO SHOWS HIS CODE WORKING PERFECTLY! have you even seen paul mcwhorter vids? he shows his published codes functioning on camera while zoomed in on the code showing letter for letter each line so you can follow along. Number=Serial.parseInt() //now "number" is equal to the serial INPUT lineĭigitalWrite(Rled,HIGH) //turn on the ledĭigitalWrite(Rled,LOW) //turn off the led While(Serial.available()=0)//WHILE serial.avail do nothing and wait Serial.println(question) //Ask for input from user/sensor Void loop() //Ask first, wait, then read to get data from serial com PinMode(Rled,OUTPUT) //assing "Rled" D6 pin as an OUTPUT Serial.begin(115200) //intialize serial com at 115200baud Int number //assign "random1" for variable value later rewriting it as this solved all my issues, BUT WHY DID I HAVE TO WRITE IT DIFFERENT THAN WHAT I WAS SHOWN ON THE LESSON? Shouldn't his code of worked no issues on my unit? 00001%ĪGAIN THE ISSUE IS WHY FOLLOWING HIS EXACT CODE DID NOT REPRODUCE THE SAME RESULTS HE SHOWED? since my first post wasn't clear enough i'm guessing. has been set to monitor for five interrupts with a while loop monitoring the analog pins. If (irrecv.That still doesn't answer why my unit isn't doing what his is so it doesn't solve my issue by even. Although both Arduino and Raspberry Pi were teaching concepts. Serial.println("IR Receiver Button Decode") IRrecv irrecv(RECEIVER) // create instance of 'irrecv'ĭecode_results results // create instance of 'decode_results' My goal is to eventually drive a DC motor that will drive my bot in different directions depending on the ir input. I can use switch case but if you hold down the ir remote button it does not repeat. LESSON 1: Simple Introduction to the Arduino LESSON 2: Simple Arduino Breadboard Tutorial LESSON 3 - Arduino For Loops and LED Circuit LESSON 4: Printing. What and how : Know about programming, basic loops, declarations,functions and most importantly classes and its peripherals,not like bookworm but like tapeworm. When the key is released, have the LED go low. I have been trying to do a simple task which is when I press and hold the ir remote button to loop a block of code, for example, make an LED go high only while holding down the key. Ok here's my first post asking for a bit of help.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |