Arduino Forum

Community => Gigs and Collaborations => Topic started by: Wozsher on Sep 24, 2017, 09:45 am

Title: Programmable Shift Light
Post by: Wozsher on Sep 24, 2017, 09:45 am
Hi. Hope this is allowed. :o
I'm looking to commission someone to design the circuit and write the code for a programmable shift light.

The rpm signal will come from a non latching hall effect sensor mounted on the engine pulley.
I nead to switch on 3 banks of different coloured led's at 3 different rpm values. If possible I would like to be able to set those values using push buttons at say 100 rpm intervals.

I hope that makes sense and if anyone is interested or has already done this please get in touch via here or at carboncopiesltd@yahoo.co.uk.

Thanks in advance.
Title: Re: Programmable Shift Light
Post by: kenwood120s on Sep 24, 2017, 09:52 am
I've suggested to the mods that they move this to Gigs and Collaborations

Title: Re: Programmable Shift Light
Post by: Wozsher on Sep 24, 2017, 09:56 am
Thank you.
Title: Re: Programmable Shift Light
Post by: Dmitron1036 on Sep 25, 2017, 11:49 am
Hello, Wozsher!
I guess the code is simple.
You need to use PulseIn function:
https://www.arduino.cc/en/Reference/PulseIn
+
if operand.
Like so:

#define a 100
#define b 200
#define c 300
#define pin 5
#define GREENLED 10
#define YELLOWLED 11
#define REDLED 12
unsigned long duration;

void loop()
{

  duration = pulseIn(pin, HIGH);
// reset leds
digitalWrite(GREENLED, LOW);
digitalWrite(YELLOWLED , LOW);
digitalWrite(REDLED , LOW);

// set leds
if(duration < a){digitalWrite(GREENLED, HIGH);}
else if(duration < b){digitalWrite(YELLOWLED , HIGH);}
else{digitalWrite(REDLED , HIGH);}

// pause
delay(200); //ms

}
Title: Re: Programmable Shift Light
Post by: Wozsher on Sep 25, 2017, 07:51 pm
Hello, Wozsher!
I guess the code is simple.
You need to use PulseIn function:
https://www.arduino.cc/en/Reference/PulseIn
+
if operand.
Like so:

#define a 100
#define b 200
#define c 300
#define pin 5
#define GREENLED 10
#define YELLOWLED 11
#define REDLED 12
unsigned long duration;

void loop()
{

  duration = pulseIn(pin, HIGH);
// reset leds
digitalWrite(GREENLED, LOW);
digitalWrite(YELLOWLED , LOW);
digitalWrite(REDLED , LOW);

// set leds
if(duration < a){digitalWrite(GREENLED, HIGH);}
else if(duration < b){digitalWrite(YELLOWLED , HIGH);}
else{digitalWrite(REDLED , HIGH);}

// pause
delay(200); //ms

}

Thank you very much for your help. I'm totally new to Arduino so this is going to be a very steep learning curve.
Title: Re: Programmable Shift Light
Post by: Wozsher on Sep 26, 2017, 09:28 am
I said I'd be back. Whilst trying to verify the code at the voidloop() point I get the following error.
voidloop was not declared in this scope.

All help appreciated. Thanks
Title: Re: Programmable Shift Light
Post by: kenwood120s on Sep 26, 2017, 10:47 am
Hmmmm I get a different error, namely that there's no setup(), which is because your contractor ;) gave you a sketch with no setup().

If I put this line in:

Code: [Select]
void setup(){}

... it at least compiles. But an empty setup() won't be correct since it needs pinModes() at least to set the leds to outputs.

Post the actual code you can't compile. (edit: do you actually have voidloop writeen like that with no space, not void loop?)



Title: Re: Programmable Shift Light
Post by: Wozsher on Sep 26, 2017, 10:57 am
Thanks for the quick reply.
I have no space in voidloop.
On my phone at the moment but I'll post up the full code asap. Cheers
Title: Re: Programmable Shift Light
Post by: Dmitron1036 on Sep 27, 2017, 06:05 pm
The full code is like this:
// define values here:
#define a 600000 // 1000000us * 60 s/m /100rpm
#define b 300000 // 1000000 * 60/200
#define c 200000 // 1000000 * 60/300
#define pin 5     // the digital pin to read pulse duration
#define GREENLED 10   // Digital pin nomber
#define YELLOWLED 11  // Digital pin nomber
#define REDLED 12     // Digital pin nomber
// custom project variables:
unsigned long duration;///< pulse duration, the length of the pulse (in microseconds) or 0 if no pulse is completed before the timeout (unsigned long)
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(GREENLED, OUTPUT);
  pinMode(YELLOWLED, OUTPUT);
  pinMode(REDLED, OUTPUT);
  // serial port init
  Serial.begin(115200);//115200 baud!!!
}

// the loop function runs over and over again forever
void loop()
{

  duration = pulseIn(pin, HIGH);
// reset leds
digitalWrite(GREENLED, LOW);
digitalWrite(YELLOWLED , LOW);
digitalWrite(REDLED , LOW);

// set leds
if(duration < a){digitalWrite(GREENLED, HIGH);}
else if(duration < b){digitalWrite(YELLOWLED , HIGH);}
else{digitalWrite(REDLED , HIGH);}

// pause
delay(200); //ms

}
Title: Re: Programmable Shift Light
Post by: kenwood120s on Sep 27, 2017, 06:09 pm
Well that compiles because it has the space in "void loop" and has a setup() unlike what you posted before.

So I have no idea what you're asking now.

Title: Re: Programmable Shift Light
Post by: Wozsher on Sep 28, 2017, 08:01 am
Dmitron 1036 thanks for the new code.
I'm trying to adapt it to my needs and below is where the problems start.
I'm totally new to this so please be gentle
Title: Re: Programmable Shift Light
Post by: Dmitron1036 on Sep 28, 2017, 05:25 pm
As I see, In my code:

digitalWrite(YELLOWLED , LOW);

and in your code:

digitalWrite(YELLOWLED . LOW);

- point instead of comma.