Hello,
I am doing project of remote engine control by website. But first what I have to do is make a program od arduino.
The frequency will be set via the browser and engine will be obvers and revers.
First I make a diod control prototype.
Why when I start a program, both diod are turned ON? I can't have like this because it wil fuse later.
When I write something on SerialConsol then program is working but:
Why void loop is not looping? Makes loop only once.
Welcome to the Forum. Your English is just fine. It would be good for you to read this. Pay particular attention to point 6. I have formatted/posted your code for you so that others may see it. You'll get more help that way as many will not follow a link.
#define awersSilnika 8
#define rewersSilnika 9
long odebraneDane = 0;
long czasPracySilnika = 100000; // 100 sekund
void setup()
{
Serial.setTimeout(czasPracySilnika); //po tym czasie SerialparseInt zwraca zero, bez ustawienia tego parametru zwraca zero po sekundzie.
Serial.begin(9600); //Uruchomienie komunikacji portu szeregowego
pinMode(awersSilnika, OUTPUT); //Konfiguracja wyjść
pinMode(rewersSilnika, OUTPUT);
digitalWrite(awersSilnika, LOW); //stan poczatkowy LOW
digitalWrite(rewersSilnika, LOW);
}
void loop()
{
if(Serial.available() > 0)
{
odebraneDane = Serial.parseInt();
Serial.println(odebraneDane);
}
digitalWrite(awersSilnika, HIGH);
delay(odebraneDane);
digitalWrite(awersSilnika, LOW);
delay(odebraneDane);
digitalWrite(rewersSilnika, HIGH);
delay(odebraneDane);
digitalWrite(rewersSilnika, LOW);
delay(odebraneDane);
Diod wired is like here: Take screenshots in Firefox | Firefox Help
but I have a two diods and without button.
Without function IF program is working normaly and diod are blinking.
proof is in diod. Diod is blinking: turn on, off, on, off and stop.
Most likely you are not sending a terminator on the wire, so Serial.parseInt() will wait for timeout or another character.
So if you're sending "123" then Serial.parseInt() will not return until 100 seconds have passed, but if you send "123x" the thing will work. Either way, 100 seconds seems like a heck of a timeout.
So if you're sending "123" then Serial.parseInt() will not return until 100 seconds have passed, but if you send "123x" the thing will work. Either way, 100 seconds seems like a heck of a timeout.
hmm... then what I have to use there to write numbers?
Serial.parseInt return after one second zero if I not declare Serial.setTimeout
Initial characters that are not digits or a minus sign, are skipped; Parsing stops when no characters have been read for a configurable time-out value, or a non-digit is read; If no valid digits were read when the time-out (see Serial.setTimeout()) occurs, 0 is returned;
So parseInt() will read characters until it encounters a non-digit OR timeout is reached. The default timeout is 1 second.
I guess that you are sending stuff across the serial port to the board - otherwise the code will always timeout. So make sure that each integer you are sending is followed by a non-digit character.
So make sure that each integer you are sending is followed by a non-digit character.
If you are using the Serial Monitor application to send data, it can be configured to append a carriage return or line feed or both to what you type in, all of which qualify as "a non-digit character".
If you are using some other app to send the data, make that app send a non-digit after the value.