hello,
I want to make a loop in a function from a remote function.
#include <IRremote.h>
int i = 10;
int RECV_PIN = 6; //ontvangst punt is 11
IRrecv irrecv(RECV_PIN); //library deze pin
decode_results results; //zet om naar getallen
void setup() {
irrecv.enableIRIn(); //setup ontvangst punt
pinMode(i, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (irrecv.decode(&results)) { //als een ir signaal is gedetecteerd
long int decCode = results.value; //als het zo is maak er een variabele van
Serial.println(decCode);
irrecv.resume(); // begin opnieuw met zoeken naar ir signaal
}
switch (results.value) { //afhankelijk van he ir signaal doe dit....
case 16738455://omhoog //kijk of er zo,n signaal komt van de afstandbediening, zo ja doet wat er onder staat
digitalWrite(i, HIGH);
delay(100);
digitalWrite(i, LOW);
delay(100);
break; //niet verder kijken of er nog meer opdrachten zijn voor dit signaal
}
}
I want to repeat the
digitalWrite(i, HIGH);
delay(100);
digitalWrite(i, LOW);
delay(100);
How can I do this?
Use the "BlinkWithoutDelay" example to see how to do a blinking pattern without spending all your processing time in delay(). Then add a variable to enable and disable the blinking code. Then turn that on an off with the remote control input.
I want to repeat the
How many times? Computers are stupid, you know. They will only do what you tell them to do.
When I use the blinkwithoutdelay it is only runs once, when I press a button on the remote the led goes on and when I press the button again the led goes off. So that doesn't work.
I want the program to run unlimited like the void loop.
ikke1:
I want the program to run unlimited like the void loop.
You can't. In order to perform more than one task at a time, the loop() function has to be the only loop. You have to use flags, variables and if statements in place of for and while loops (in general).
I found something that does not repeat unlimited but it does repeat much.
for(int i = 0; i<99999999999999999; i++)
But can I use int with such numbers?
ikke1:
I found something that does not repeat unlimited but it does repeat much.
for(int i = 0; i<99999999999999999; i++)
But can I use int with such numbers?
The loop() compatible version of that would be:
int i=0;
loop()
{
if (i<9999)
{
{ } //stuff that you would do in the for loop here
i++;
}
...
}
No, ints can not store such a big number.
You need to separate reading serial data from using serial data.
if(Serial.available() > 0)
{
char c = Serial.read();
if(c == 'b')
blink = true;
if(c == 's')
blink = false;
}
if(blink)
{
// Use the blink with delay example to determine what to do here
}
blink would be a boolean variable, with global scope, initialized to false.