// generated by mBlock5 for <your product>
// codes make you happy
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#include <Servo.h>
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
float Pot_Value = 0;
float RED = 0;
float BLUE = 0;
float GREEN = 0;
float ANGLE = 0;
float Current_state = 0;
float New_State = 0;
float Previous_State = 0;
Servo servo_3;
void _delay(float seconds) {
long endTime = millis() + seconds * 1000;
while(millis() < endTime) _loop();
}
void setup() {
lcd.init();
pinMode(A0+0,INPUT);
servo_3.attach(3);
pinMode(11,OUTPUT);
pinMode(10,OUTPUT);
pinMode(6,OUTPUT);
Serial.begin(115200);
lcd.backlight();
while(1) {
for(int count=0;count<1;count++){
Current_state = 0;
}
Pot_Value = analogRead(A0+0);
ANGLE = map(Pot_Value, 0, 1023, 0, 180);
servo_3.write(map(Pot_Value, 0, 1023, 0, 180));
if((Pot_Value > 0) && (Pot_Value < 341)){
RED = map(Pot_Value, 0, 341, 255, 0);
BLUE = map(Pot_Value, 0, 341, 0, 255);
GREEN = 0;
}
if((Pot_Value > 341) && (Pot_Value < 682)){
BLUE = map(Pot_Value, 341, 682, 255, 0);
GREEN = map(Pot_Value, 341, 682, 0, 255);
RED = 0;
}
if((Pot_Value > 682) && (Pot_Value < 1023)){
BLUE = map(Pot_Value, 682, 1023, 0, 255);
RED = map(Pot_Value, 682, 1023, 0, 255);
GREEN = 255;
}
analogWrite(11,RED);
analogWrite(10,GREEN);
analogWrite(6,BLUE);
if(!((Pot_Value == Current_state))){
lcd.clear();
lcd.print(String("ANGLE:") + String(ANGLE));
Current_state = Pot_Value;
Serial.println(String("POT VALUE: ") + String(Pot_Value));
Serial.println(String("RED VALUE: ") + String(RED));
Serial.println(String("GREEN VALUE: ") + String(GREEN));
Serial.println(String("BLUE VALUE: ") + String(BLUE));
Serial.println(String("SERVO POSITION: ") + String(map(Pot_Value, 0, 1023, 0, 180)));
}
_loop();
}
}
void _loop() {
}
void loop() {
_loop();
}