I do not know how to program my arduino, so that together with the potentiometer the servo moves and the led light turns red for degrees greater than 120 and less than or equal to 180, green for more than 60 and less than or equal to 120, and blue for grades below 60. So far I have this part of the code, but it doesn't work
#include <Servo.h>
Servo mYServo;
int potpin = 0;
int val;
void setup()
{
// put your setup code here, to run once;
Serial.begin(30);
pinMode (5, OUTPUT);
pinMode (6, OUTPUT);
pinMode (7, OUTPUT);
miServo.attach(9);
}
void loop()
{
// put your main code here, to run repeatedly;
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 180);
miServo.write(val);
if ( val>120; && val<180; or val==180)
{
//RED
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
miServo.attach(9);
}
if (val>60; && val<120; or val==120)
{
//BLUE
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
miServo.attach(9);
}
if ( val < 60; or val == 60);
{
//GREEN
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(4,LOW);
}
delay(30);