I'm attempting to display a tweet when a sharp IR sensor "sees" a person in front of the project. The problem I'm having: connecting to twitter, displaying the tweet, etc takes a while and the sensor starts reading again before the tweet is fully read from the API, resulting in no tweets displayed.
Code like this works fine:
#include <SPI.h>
void setup() {
Serial.begin(9600);
}
void loop() {
//while there is no one there, read the sensor until there is someone there
while (analogRead(0) < 100) {
Serial.println(analogRead(0));
}
//now that there is someone there, do something
Serial.println("sensor is now greater than 100");
}
But code like this seems to move to fast for the twitter part
#include <SPI.h>
void setup() {
Serial.begin(9600);
}
void loop() {
//while there is no one there, read the sensor until there is someone there
while (analogRead(0) < 100) {
Serial.println(analogRead(0));
}
//now that there is someone there, do something that takes a while
<pseudocode> connect to twitter API, get a tweet, display it on LCD </pseudocode>
}
Thoughts? Does the loop belong at the end? Thanks from a code newbie!