Hi there,
I've cracked that problem so the code is now uploaded. I have a problem with the code now perhaps you can help me?
#include "Wire.h"
#include "SRF02.h"
SRF02 srf02[4] = {
SRF02(0x70, SRF02_CENTIMETERS),
SRF02(0x71, SRF02_CENTIMETERS),
SRF02(0x72, SRF02_CENTIMETERS),
SRF02(0x73, SRF02_CENTIMETERS)
};
unsigned long nextPrint = 0;
void setup()
{
Serial.begin(9600);
Wire.begin();
}
void loop()
{
SRF02::update();
if (millis() > nextPrint)
{
Serial.print(srf02[0].read());
Serial.print(",");
Serial.print(srf02[1].read());
Serial.print(",");
Serial.print(srf02[2].read());
Serial.print(",");
Serial.print(srf02[3].read());
Serial.println();
nextPrint = millis () + 1000;
}
// 'When sensors 70, 71, 72 & 73 take readings 0-50 fade in LED strip on port 5, 0 being the lowest, 50 being the brightest.
if (srf02[0].read() >=0 && srf02[0].read() <= 50)
analogWrite(5, map(srf02[0].read(), 0, 50, 0, 255));
if (srf02[1].read() >=0 && srf02[1].read() <= 50)
analogWrite(5, map(srf02[1].read(), 0, 50, 0, 255));
if (srf02[2].read() >=0 && srf02[2].read() <= 50)
analogWrite(5, map(srf02[2].read(), 0, 50, 0, 255));
if (srf02[3].read() >=0 && srf02[3].read() <= 50)
analogWrite(5, map(srf02[3].read(), 0, 50, 0, 255));
// When sensors 70, 71, 72 & 73 take readings 50-100, keep strip 5 on its brightest and fade in strip on port 6, 50 beng the lowest, 100 being the brightest.'
if (srf02[0].read() >=50 && srf02[0].read() <= 100) {
digitalWrite(5, HIGH);
analogWrite(6, map(srf02[0].read(), 50, 100, 0, 255));
}
if (srf02[1].read() >=50 && srf02[1].read() <= 100) {
digitalWrite(5, HIGH);
analogWrite(6, map(srf02[1].read(), 50, 100, 0, 255));
}
if (srf02[2].read() >=50 && srf02[2].read() <= 100) {
digitalWrite(5, HIGH);
analogWrite(6, map(srf02[2].read(), 50, 100, 0, 255));
}
if (srf02[3].read() >=50 && srf02[3].read() <= 100) {
digitalWrite(5, HIGH);
analogWrite(6, map(srf02[3].read(), 50, 100, 0, 255));
}
}
It is fading my lights on and off how I wish however when the reading goes above 100 the lights seem to just stay on, is there a way to remedy this in the code?
thanks for your help