While it is easy to create a blinking LED with the delay() function, and many sketches use short delays for such tasks as switch debouncing, the use of delay() in a sketch has significant drawbacks. No other reading of sensors, mathematical calculations, or pin manipulation can go on during the delay function, so in effect, it brings most other activity to a halt. For alternative approaches to controlling timing see the millis() function and the sketch sited below. More knowledgeable programmers usually avoid the use of delay() for timing of events longer than 10's of milliseconds unless the Arduino sketch is very simple.
my piece of code needs to be at the place of "repeat me()"?
#include <SimpleTimer.h>
// the timer object
SimpleTimer timer;
// a function to be executed periodically
void myDataStream() {
....
....
....
}
void setup() {
Serial.begin(9600);
timer.setInterval(1000, myDataStream);
}
void loop() {
timer.run();
}
and how can I send data as a stream?
I think i get it for the timer.
I mean,when I open "serial monitor" in arduino, the data are not like that: X1,X2,X3,X4 etc.
And this what i want.
The database where I am dumping the data into are "smallint" type
The screen on serial monitor displays this:
34,000000000,0,1
163
,178)
instead of
34,0,0,1,163,178.
My supervisor advised me to use integer
void ReadSensors()
{
Switch1 = digitalRead(54); //Variable to store the resistance value
Switch2 = digitalRead(55);
if(Switch1==HIGH)
// if (analogRead(Good) > 300) // Good Sensor Activated
{
digitalWrite(2,HIGH); // Green LED On
GoodCounter++; // Increment Good Counter
sDataField1 = String(1, DEC);
}
else
{
digitalWrite(2,LOW);
sDataField1 = String(0, DEC);
}
if(Switch2==HIGH)
//if (analogRead(Bad) > 300) // Bad Sensor Activated
{
digitalWrite(5,HIGH); // Red LED On
BadCounter++; // Increment Bad Counter
sDataField2 = String (1, DEC);
}
else
{
digitalWrite(5, LOW);
sDataField2 = String(0, DEC);
}
...
...
...
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?