Hi there,
I have 4 srf02 ultrasonic range finders hooked up to my arduino uno which are feeding back data to my serial monitor. I also have two 5m strips of leds attached to ports 5 and 6. I am using the code below to use the data from my range finders to fade in and out my leds depending on the readings.
However I keep getting an error message and cannot work out what the problem is see code:
#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));
}
and error message:
allsensorfeedback:38: error: expected unqualified-id before 'if'
allsensorfeedback:40: error: expected unqualified-id before 'if'
allsensorfeedback:42: error: expected unqualified-id before 'if'
allsensorfeedback:44: error: expected unqualified-id before 'if'
allsensorfeedback:51: error: expected unqualified-id before 'if'
allsensorfeedback:55: error: expected unqualified-id before 'if'
allsensorfeedback:59: error: expected unqualified-id before 'if'
allsensorfeedback:63: error: expected unqualified-id before 'if'
If anyone can help I would be much obliged,
many thanks,
A