Writing code assistance

I am new to Arduino and code writing. I have a project that I would like to have code written for. If anyone is up for the challenge here is the sequence of events that needs to happen.

I have an array of 8 rgb led lights.
they are common anode.
I am using tip120’s to switch the load, this part works great.
here are the conditions

  1. Estop +5vdc input (3) = blue and green are off, red is on
  2. axismove ground input (2) = blue and red are off, green fades on and off
  3. power +5vdc input (12) = blue, red, and green are on
  4. blue = output (9)
  5. red = output (6)
  6. green = output (5)

Any help with this code would be greatly appreciated. ;D

If you can supply a full schematic and a bottle of rum I may consider it.

Seems dirt simple:

byte blue = 9;
byte red = 6;
byte green = 5;
byte estop = 3;
byte axismove = 2
byte power = 12;
void setup(){
pinMode (blue, OUTPUT);
pinMode (red, OUTPUT);
pinMode (green, OUTPUT);
pinMode (estop, INPUT_PULLP);
pinMode (axismove, INPUT_PULLUP);
pinMode (power, INPUT_PULLUP);
}
void loop(){
if (digitalRead(estop) == HIGH){
digitalWrite (red, HIGH);
digitalWrite (blue, LOW);
digitalWrite (green, LOW);
}
if (digitalRead(axismove == LOW){
digitalWrite (red, LOW);
digitalWrite (blue, LOW);
digitalWrite (green, HIGH);
}
if (digitalRead(power) == HIGH){
digitalWrite (red, HIGH);
digitalWrite (blue, HIGH);
digitalWrite (green, HIGH);
}
}

No fading, but then you get what you pay for.

thanks crossroads,

This looks logical, however i am getting a error when compiling.
'INPUT_PULLUP' was not declared in this scope.
I will probably get the same error with all three 'INPUT_PULLUP' statements

Thank you for taking the time to assist me with this.

Thanks KenF,

I could try to digitally write you some rum to your e mail. lol

INPUT_PULLUP has been supported since IDE 1.0.
What version are you running?
If you have external pullups or pulldowns, change those lines to just INPUT.

Or use
pinMode (estop, INPUT);
digitalWrite (estop, HIGH); // enables internal pullup

I think the INPUT_PULLUP problem is that the OP has probably copied the typo " pinMode (estop, INPUT_PULLP); " :-*

Bernie

Ah, a little typo in my example.

I am working with a Arduino micro, and running 1.0.6.

the power if statement seems to work ...... in 12 has an external 10K resistor connected to ground
the estop does not change when +5 is applied to input 3.....in 3 has a external 10K resistor connected to ground
the axismove does not change when ground is applied to input 2....in 2 has no resistor on it

thanks Bernie,

Got the typo changed and now compiling ok but the statements in the previous post are still occurring.

I am grateful for everyones help

Change these

pinMode (estop, INPUT);
pinMode (axismove, INPUT_PULLUP);
pinMode (power, INPUT);

You fixed this typo also? A ) was left out

if (digitalRead(axismove) == LOW){

Only 1 switch at a time is moved to the active position?

Hi CrossRoads,

Ok I changed the PULLUP text in pinmode

yes I corrected the second typo with axismove.

the power switch will remain active as long as the arduino has power connected

the estop switch will become active when someone hits the estop button

the axis move switch will be active whenever any of the 4 axis are moving

so, in short there will be conditions when the axismove is active and someone hits the estop button and it becomes active.

the estop and axismove would be able to overwrite the power switch

So really you want to test for estop or axismove, then turn off lights as needed, otherwise turn all 3 on. Something like:

void loop(){
if ((digitalRead(estop) == HIGH) ||  (digitalRead(axismove == LOW)) {
if (digitalRead(estop) == HIGH){
digitalWrite (red, HIGH);
digitalWrite (blue, LOW);
digitalWrite (green, LOW);
}
if (digitalRead(axismove == LOW){
digitalWrite (red, LOW);
digitalWrite (blue, LOW);
digitalWrite (green, HIGH);
}
}
else{
digitalWrite (red, HIGH);
digitalWrite (blue, HIGH);
digitalWrite (green, HIGH);
}
}

im getting a compile error first line

if ((digitalRead(estop) == HIGH) || (digitalRead(axismove == LOW)) {

error
expected ')' before ')' token

The error message is quite clear. Count the opens and count the closes you'll soon spot the mistake.

if ((digitalRead(estop) == HIGH) ||  (digitalRead(axismove) == LOW) {

Thanks KenF,

Corrected compile error.

Uploaded

when board is on and power input has +5vdc

Only green is on

should be all three to produce white

When i make estop active (+5vdc) red comes on as it should
blue and green go off as they should

Check your wiring, maybe write an even simpler example to ensure the LEDs can all light up.

Tweak the logic some. This is not a difficult project to understand.

ok thank you for your time CrossRoads