Show Posts
|
|
Pages: 1 2 [3] 4 5
|
|
32
|
Using Arduino / Project Guidance / Re: Heart rate monitor
|
on: September 17, 2011, 01:36:55 pm
|
I know, but I don't have the strap.
The strap "T31" cost only ~20$ at any Healt/sport boutique near you. It is good for two years if used at average one hour a day.
|
|
|
|
|
34
|
Community / Bar Sport / Re: Your latest purchase
|
on: September 17, 2011, 11:51:39 am
|
Those displays are pretty cool! When you have a look at the command set, it kinda leaves you wondering what your Arduino is going to be doing! They have multiple UARTS, SPI, I2C, GPIO pins. I think the language has built in support for parsing NMEA sentences.
Wow! didnt know that. Really cool device indeed.
|
|
|
|
|
40
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: Function for multiple blinking LED instances
|
on: June 29, 2009, 07:47:27 pm
|
The problem with the original post is that the 3 variables - state, ledON, ledOFF - need to be in an array. The way you have it, each of the 3 pins are using the same variables, and it's messing things up. I put together a corrected version, and even tried it, so I know it works Arrrgh!! Thanks, i was close from the beginning :o
|
|
|
|
|
42
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: Function for multiple blinking LED instances
|
on: June 29, 2009, 05:22:27 pm
|
|
I'm using struct now but i still unable to use only one function flashled(led_id) to pass argument of the led id i want to blink !!
I should never stop programming 22 years ago :-[
long time = 0; typedef struct BlinkPin{ byte ledpin; unsigned int ledON; unsigned int ledOFF; unsigned long timeON; unsigned long timeOFF; boolean state; };
BlinkPin led1 = {10,25,1000,0,0,0}; BlinkPin led2 = {11,800,500,0,0,0}; BlinkPin led3 = {12,25,250,0,0,0};
void setup(){ Serial.begin(38400); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(12, OUTPUT); }
void loop(){ flashled1(); flashled2(); flashled3(); }
void flashled1() { time = millis(); if (led1.state == HIGH) { if (time >= led1.timeOFF) { led1.state = LOW; Serial.print(led1.state); digitalWrite(led1.ledpin, led1.state); led1.timeON = led1.timeOFF + led1.ledOFF; } } else { if (led1.state == LOW){ if (time >= led1.timeON) { led1.timeON = millis(); led1.state = HIGH; Serial.print(led1.state); digitalWrite(led1.ledpin, led1.state); led1.timeOFF = led1.timeON + led1.ledON; } } } }
void flashled2() { time = millis(); if (led2.state == HIGH) { if (time >= led2.timeOFF) { led2.state = LOW; Serial.print(led2.state); digitalWrite(led2.ledpin, led2.state); led2.timeON = led2.timeOFF + led2.ledOFF; } } else { if (led2.state == LOW){ if (time >= led2.timeON) { led2.timeON = millis(); led2.state = HIGH; Serial.print(led2.state); digitalWrite(led2.ledpin, led2.state); led2.timeOFF = led2.timeON + led2.ledON; } } } }
void flashled3() { time = millis(); if (led3.state == HIGH) { if (time >= led3.timeOFF) { led3.state = LOW; Serial.print(led3.state); digitalWrite(led3.ledpin, led3.state); led3.timeON = led3.timeOFF + led3.ledOFF; } } else { if (led3.state == LOW){ if (time >= led3.timeON) { led3.timeON = millis(); led3.state = HIGH; Serial.print(led3.state); digitalWrite(led3.ledpin, led3.state); led3.timeOFF = led3.timeON + led3.ledON; } } } }
This should look like this :
flashled(led1); flashled(led2); flashled(led3);
void flashled(led_id) { time = millis(); if (led_id.state == HIGH) { if (time >= led_id.timeOFF) { led_id.state = LOW; Serial.print(led_id.state); digitalWrite(led_id.ledpin, led_id.state); led_id.timeON = led_id.timeOFF + led_id.ledOFF; } } else { if (led_id.state == LOW){ if (time >= led_id.timeON) { led_id.timeON = millis(); led_id.state = HIGH; Serial.print(led1.state); digitalWrite(led_id.ledpin, led_id.state); led_id.timeOFF = led_id.timeON + led_id.ledON; } } } }
|
|
|
|
|
43
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: Function for multiple blinking LED instances
|
on: June 29, 2009, 05:11:10 am
|
Without knowing what you want, I threw some code togehter. Might be helpful, might not. But I thing you could get an idea of how one way to implement this could look. Alexander, Thanks for the idea but i don't think i could do what i want with it. I may try indeed and i will. :  Here's exactly my need: 1- The number of led can be more than 3 and i can deal with this code myself. 2- The blinking is the most important behaviour in the program and this is where i'm looking for help. Some led will lite up for 10 millis and snuff out for 800 millis or lite up for 200 millis and snuff out for 254 millis etc... anytime in the program. Values are between 15 millis and 5000 millis. It is purely for visual purpose monitoring. 3- I thought that a simple function would be enough for that multiple blinking behaviour.
|
|
|
|
|
44
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: Function for multiple blinking LED instances
|
on: June 29, 2009, 03:47:36 am
|
|
The code i first wrote for this example is this. You see the leds blinks with each states correctly. But my code is bad for a better overall program, i wish i could use only one function call instead.
long time = 0; long timeON1 = 0; long timeOFF1 = 0; int state1 = LOW; long timeON2 = 0; long timeOFF2 = 0; int state2 = LOW; long timeON3 = 0; long timeOFF3 = 0;int state3 = LOW;
void setup() { Serial.begin(38400); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(12, OUTPUT); }
void loop() { flashled1(10, 15, 400); flashled2(11, 150, 600); flashled3(12, 400, 1000); }
void flashled1(int ledpin, int ledON, int ledOFF) { time = millis(); if (state1 == HIGH) { if (time >= timeOFF1) { state1 = LOW; Serial.print(state1); digitalWrite(ledpin, state1); timeON1 = timeOFF1 + ledOFF; } } else { if (state1 == LOW){ if (time >= timeON1) { timeON1 = millis(); state1 = HIGH; Serial.print(state1); digitalWrite(ledpin, state1); timeOFF1 = timeON1 + ledON; } } } }
void flashled2(int ledpin, int ledON, int ledOFF) { time = millis(); if (state2 == HIGH) { if (time >= timeOFF2) { state2 = LOW; Serial.print(state2); digitalWrite(ledpin, state2); timeON2 = timeOFF2 + ledOFF; } } else { if (state2 == LOW){ if (time >= timeON2) { timeON2 = millis(); state2 = HIGH; Serial.print(state2); digitalWrite(ledpin, state2); timeOFF2 = timeON2 + ledON; } } } }
void flashled3(int ledpin, int ledON, int ledOFF) { time = millis(); if (state3 == HIGH) { if (time >= timeOFF3) { state3 = LOW; Serial.print(state3); digitalWrite(ledpin, state3); timeON3 = timeOFF3 + ledOFF; } } else { if (state3 == LOW){ if (time >= timeON3) { timeON3 = millis(); state3 = HIGH; Serial.print(state3); digitalWrite(ledpin, state3); timeOFF3 = timeON3 + ledON; } } } }
|
|
|
|
|