NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Button ipod help
June 09, 2011 by missle3944 |
Hi guys, I have run into a problem with a cool project that I made up today. Does anyone know how to turn a pin on high just once instead of looping through the while loop. My problem is that when the temp_avg gets to a certan point it pulls a pin high. but i only want it to pull it once in the if statement and not loop it. So i only whant it to turn on once each time the temp is achieved. Here's my code if anyone can help :)
|
---|---|
June 09, 2011 by met_fredrik |
Hi! It is a bit unclear to me what you are really asking. But if i understand you correctly you want the pin to turn on and off inside the same if statement? To do this, simply turn the pin on and off. if (temp_avg < 350) {.
} I hope I understood you correctly! |
June 09, 2011 by missle3944 |
Hi met_fredrik, I already tried that but what I really mean is when the temp is less than 350 I only want it to blink once and not continually loop through it. It's a funny question. Maybe I'll try it in the main loop -missle3944 |
June 09, 2011 by Ralphxyz |
missle3944 you might want to use ISR(ADC_vect), that is the ADC Interrupt. Also if you only want the if statement to run once you can run it in your main but then you have to figure out a reset to do it again in the future. I think using the interrupt might solve most problems for you. That's vector 22 ADC program complete. You might want to Google "AVR adc interrupt" to see lots of discussions. Ralph Ralph |
June 09, 2011 by Rick_S |
Or, just use a flag...
May not be fully correct syntax wise... kinda did it on the fly... but you should get the idea.. Rick |
Please log in to post a reply.
Did you know that NerdKits make a great parent/child activity? Learn more...
|