Okay, its been a while and that all works great,
Except, now i need some more help.
The 'H' and sensor work together perfectly, and now i need to add extra LED's into the equation. So around the outside of the pad is a warning border with 8 yellow LED's, and on each of the corners will be a green and red led.
I need it so that when it is greater than 80 that the yellow LED's are off, and that the whole time the red and green LED's blink opposite each other.
I copied the blink code and put it into my code, so as to make the yellows blink, except because of the delay in the blink code changes the delay of my sensor part. i need help in making them both work and if the way i have coded will work out, was going with the idea of putting the Red, Green and Yellow LED's onto separate pins. Oh and the yellow LED's are wired in both series and parallel whilst i will wire the red and green in just series.
Bellow is my full code.
// Complete Helipad Code
#define REDPIN 5 // Defines the pin attached to colour
#define GREENPIN 6
#define BLUEPIN 3
// IR Sensor
int IRpin = 1; // analog pin for reading the IR sensor
void setup() {
Serial.begin(9600); // start the serial port
// RGB Strip
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
// Yellow LEDs
pinMode(13, OUTPUT);
}
void loop() {
// IR Sensor
float volts = analogRead(IRpin)*0.0048828125; // Value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
float distance = 27*pow(volts, -1.10); // Worked out from graph 65 = theretical distance / (1/Volts)S - luckylarry.co.uk
Serial.println(distance); // Print the distance
delay(100); // Arbitary wait ti0me.
// RGB Strip Colours
if (distance > 80 ) { // Dependeing on reading from sensor, change colour of strip.
analogWrite(REDPIN, 255); // Starting on White
analogWrite(GREENPIN, 255);
analogWrite(BLUEPIN, 255);
}
if (distance <= 80 && distance > 75) {
analogWrite(REDPIN, 0);
analogWrite(GREENPIN, 255);
analogWrite(BLUEPIN, 100);
}
if (distance <= 75 && distance > 70 ) {
analogWrite(REDPIN, 255);
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN, 128);
}
if (distance <= 70 && distance > 65 ) {
analogWrite(REDPIN, 255);
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN, 255);
}
if (distance <= 65 && distance > 60 ) {
analogWrite(REDPIN, 128);
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN, 255);
}
if (distance <= 60 && distance > 55 ) {
analogWrite(REDPIN, 0);
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN, 255);
}
if (distance <= 55 && distance > 50 ) {
analogWrite(REDPIN, 0);
analogWrite(GREENPIN, 128);
analogWrite(BLUEPIN, 255);
}
if (distance <= 50 && distance > 45 ) {
analogWrite(REDPIN, 0);
analogWrite(GREENPIN, 255);
analogWrite(BLUEPIN, 255);
}
if (distance <= 45 && distance > 40 ) {
analogWrite(REDPIN, 0);
analogWrite(GREENPIN, 255);
analogWrite(BLUEPIN, 128);
}
if (distance <= 40 && distance > 35 ) {
analogWrite(REDPIN, 0);
analogWrite(GREENPIN, 255);
analogWrite(BLUEPIN, 0);
}
if (distance <= 35 && distance > 30 ) {
analogWrite(REDPIN, 128);
analogWrite(GREENPIN, 255);
analogWrite(BLUEPIN, 0);
}
if (distance <= 30 && distance > 25 ) {
analogWrite(REDPIN, 255);
analogWrite(GREENPIN, 255);
analogWrite(BLUEPIN, 0);
}
if (distance <= 25 && distance > 20 ) {
analogWrite(REDPIN, 255);
analogWrite(GREENPIN, 128);
analogWrite(BLUEPIN, 0);
}
if (distance <= 20) { // Ending on Red
analogWrite(REDPIN, 255);
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN, 0);
}
// Yellow LEDs (Controls the warning border LEDs)
if (distance <= 80) {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}
}