Hi there,
I managed to solve that problem that i had before but have managed to get myslef into a silly situation: I am now at a gallery installing my work and I have not sorted out the problems with the code that I had before I made my sculpture itself! Too much to think about I think!
So I could really use some help!
The 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 sensor's 70, 71, 72 & 73 take a reading between 0-50 turn on LED strip on port 5.
if (srf02[0].read() >=0 && srf02[0].read() <= 50)
digitalWrite(5, HIGH);
if (srf02[1].read() >=0 && srf02[1].read() <= 50)
digitalWrite(5, HIGH);
if (srf02[2].read() >=0 && srf02[2].read() <= 50)
digitalWrite(5, HIGH);
if (srf02[3].read() >=0 && srf02[3].read() <= 50)
digitalWrite(5, HIGH);
// When sensor's 70, 71, 72 & 73 take a reading between 50-100, keep on LED strip 5 and also turn on the LED strip on port 6.'
if (srf02[0].read() >=50 && srf02[0].read() <= 100) {
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
}
if (srf02[1].read() >=50 && srf02[1].read() <= 100) {
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
}
if (srf02[2].read() >=50 && srf02[2].read() <= 100) {
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
}
if (srf02[3].read() >=50 && srf02[3].read() <= 100) {
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
}
// I would be happy to have this communication going first but ultimately I actually want
// the readings to fade in and out my LEDs, see below:
// '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(4, map(srf02[0].read(), 0, 50, 0, 255));
if (srf02[1].read() >=0 && srf02[1].read() <= 50)
analogWrite(4, map(srf02[1].read(), 0, 50, 0, 255));
if (srf02[2].read() >=0 && srf02[2].read() <= 50)
analogWrite(4, map(srf02[2].read(), 0, 50, 0, 255));
if (srf02[3].read() >=0 && srf02[3].read() <= 50)
analogWrite(4, 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(4, HIGH);
analogWrite(5, map(srf02[0].read(), 50, 100, 0, 255));
}
if (srf02[1].read() >=50 && srf02[1].read() <= 100) {
digitalWrite(4, HIGH);
analogWrite(5, map(srf02[1].read(), 50, 100, 0, 255));
}
if (srf02[2].read() >=50 && srf02[2].read() <= 100) {
digitalWrite(4, HIGH);
analogWrite(5, map(srf02[2].read(), 50, 100, 0, 255));
}
if (srf02[3].read() >=50 && srf02[3].read() <= 100) {
digitalWrite(4, HIGH);
analogWrite(5
, map(srf02[3].read(), 50, 100, 0, 255));
}
}
My problems:
- For some reason when the sensors read above 100 the light in port 5 just stays on all the time. I beileve that i need to state in the code when sensors read above 100 keep both lights in ports 5 and 4 off.
- The lights don't appear to fade in or out - please can you indicate in the code which bit is that states the fade in and out and how to alter it.
- i would also like to know which bit in the code indicates the sensor readings as i may need to tweak these. Please can you point this out to me aswell.
If you or anyone else can help me, I would most appreciate it.
Thankyou,
Aphra