Hello,
I want to make a function that when I go to him it will blink the led I want ,in how many loops I want.
something like
int redled=12;
pinmode(redled,OUTPUT)
blinking(redled,5)
- it will blink the red led for 5 times.
how do I define the function?
I don't need it to return nothing ,just do the blinking.....
void blinkred(x,y)
{
for (int redtime=0;redtime<x;x++)
{
digitalWrite(y,HIGH);
delay (500);
digitalWrite(y,LOW);
delay (500);
}
}
thanks ,
Do you want to know how to add the parameters?
void blinkred( char c_Pin, char c_Count )
{
for (int redtime=0;redtime<c_Count;redtime++)
{
digitalWrite( c_Pin ,HIGH );
delay (500);
digitalWrite( c_Pin ,LOW );
delay (500);
}
}
//...
blinkred(redled,5);
void blinkred( char c_Pin, char c_Count )
would
void blinkred( uint8_t u_Pin, uint8_t U_Count )
be better style?
For me it is clearer that we are dealing with an unsigned number and not a character (even if the result may be the same).
const uint8_t pinLED_1 = 7;
const uint8_t pinLED_2 = 8;
const uint8_t LED_OFF = LOW;
const uint8_t LED_ON = HIGH;
const unsigned long HALF_SECOND = 500UL;
void blinkit(uint8_t pin, int count)
{
for ( int = count; i--; )
{
digitalWrite(pin, LED_ON);
delay(HALF_SECOND);
digitalWrite(pin, LED_OFF);
delay(HALF_SECOND);
}
}
void loop()
{
blinkit(pinLED_1, 3);
blinkit(pinLED_2, 5);
}
void setup()
{
pinMode(pinLED_1, OUTPUT);
pinMode(pinLED_2, OUTPUT);
}