#include // import another program, a library, to communicate #define rxpin 1 #define txpin 0 SoftwareSerial serial(rxpin,txpin); //Declaring number to the different vararibles int rxPin = 1; // this is simular to the int = setting, however this is linked to the library//rxpin int txPin = 0; int trig = 3; // had first old pins stil in code int echo = 2; long lecture_echo; long cm; int PinRed = 6; int PinBlue = 7; int PinGreen = 5; //color amount used int Red_Amount = 100; int Blue_Amount = 100; int Green_Amount = 100; void setup() { pinMode(PinRed, OUTPUT); pinMode(PinBlue, OUTPUT); pinMode(PinGreen, OUTPUT); pinMode(trig, OUTPUT); digitalWrite(trig, LOW); pinMode(echo, INPUT); serial.begin(9600); } void loop() { digitalWrite(trig, HIGH); delayMicroseconds(10); digitalWrite(trig, LOW); lecture_echo = pulseIn(echo, HIGH); cm = lecture_echo / 58; //Read the analog pin int Input_Color = cm; //map the input value to usable range for analogWrite Input_Color = map(Input_Color, 0, 50, 0, 255); //turn on and of led analogWrite(PinRed, Input_Color); analogWrite(PinBlue, -Input_Color); analogWrite(PinGreen, Input_Color -Green_Amount); serial.print ("Distance in cm: "); serial.println(cm); serial.print ("Red:"); serial.println(PinRed, Input_Color); serial.print ("blue:"); serial.println(PinBlue, -Input_Color); serial.print ("Green:"); serial.println(PinGreen, Input_Color -Green_Amount); delay(1000); }