Can you help me with my program?

Hi guys I am trying to make something with led lights and a controller and have in my mind what I want to let my arduino do but don’t know how I can program it :confused: Can you maybe help me with the program? because I can’t figure it out!

The situation:
I have a remote variable that gives signals from 700 to 2200. I want to scroll through a menu of different colors of light by going forward if the signal is under 800 and backwards if the signal is above 2100. The menu I want to make with a variable called ‘score’ (can be changed) but every value of score means another color.

for instance: score = 1 means the color red.

I want to have it that every time the remote gets to his maximum or minimum (<800 or >2100) the value of score goes 1 up or down. With that I want to also have it that if score exceeds a certain value (0 for sure and 14 for instance) that it goes to the other extreme value (so from 14 to 0 and from 0 to 14) so I can infinitely scroll through the colors.

I have tried to make this script on my own but I have not the skills for it to let it work like I want… The problems I have with the made script (posted below) are: If I reach below 800 or above 2100 the variable score doesn’t change with 1 but with 20 or so, that is ofcourse because it refreshes every 10milliseconds but how can I let it change only once and than wait until I do it another time. Second problem is the infinite scrolling capabilities, how can I let the value of score change from 14 to 0 or other way around?

Can you maybe help me with my script? Thank you :smiley:

int red = 4;
int green = 6;
int blue = 2;
int remote = 8;
int score;
void setup() {

  • Serial.begin(9600); *

  • pinMode(red, OUTPUT);*

  • pinMode(green, OUTPUT);*

  • pinMode(blue, OUTPUT);*

  • int score = 0;*

  • analogWrite(red,0);*

  • analogWrite(green,0);*

  • analogWrite(blue,0);*

}

void loop() {

  • int remoteValue = pulseIn(remote, HIGH, 25000);*
    Serial.println(remoteValue);
    Serial.println(score);
    if (remoteValue < 800) {
  • score++;*

}
if (remoteValue > 2100){

  • score–;*

}

  • analogWrite(red,250);*
  • analogWrite(green,0);*
  • analogWrite(blue,0);*
  • delay(10);*
    }

I want to have it that every time the remote gets to his maximum or minimum (<800 or >2100) the value of score goes 1 up or down.

That is not what you have programmed.

What you have written is that while the remote is above the maximum or is below the minimum (<800 or >2100) the value of score goes 1 up or down.

Look at the StateChangeDetection example in the IDE to see how to detect when a value becomes greater or less than a threshold rather than when it is greater or less than a threshold.