Why is my program breaking out of forever loop!


#1

I have been working for days trying understand why I cant program my mbot to play my tune before running the course me and my son made. It plays the song then it starts to run the course and then stops and starts playing the song again. I originally tried doing in using time; playing the song for 60 seconds and then running the course for 60 seconds. Same results, it plays tune; starts to run and then stops and plays the tune again. How is it possible it is breaking out of this forever loop!


#2

I’m not sure I understand. Are some things like that you seek?
1


#3

I tried it using the repeat until timer > 60 for the tune and not then repeating until > 60 for the mbot to run the course using the code for ultrasonic sensor and line follow sensor. It would play the the song and then it would start running and then stop and play the song again. But when I switched it and ran the course first then played the song it will do that. But I can’t get it to play the tune and then run the code inside the forever loop. It stops running and starts playing the code again. Which seems impossible


#4

Well, the way the program is structured, the myTune block would only be executed once at the beginning. The way the underlying system works, is that anything outside of the forever loop goes into the setup() method of the Arduino code that gets generated. Anything inside of the forever loop goes into the loop() method that runs continuously after the setup() method completes. My suspicion is that something is causing a reset with the effect of re-running the entire program but I’d need to get a copy of your program to confirm that. :slight_smile:


#5

I figure it out!!! So I attached a robotic arm to my mbot; different board but I used a splitter and powered them both from the mbot battery pack. Well that was the problem! It wasn’t but getting sufficient power! So even though it would power on and run it made it look like it was jumping out of the loop but you are exactly right it was restarting the program! Put them on separate 9v’s and everything works perfectly!


#6

Good find! From my own experience, I’ve always had to power robotic arms from a separate source because the current draw will cause a brown-out situation which, as you discovered, will effectively cause the board to reboot as if it had experienced a power reset.