programming for interactive light sculpture

Hi there,

I am creating an interactive sculpture. I have 4 srf02 ultrasonic range finders each with with identifiable ids, 70, 71, 72 and 73. These sensors are hooked up to my arduino and via the A5 and A4 channels and feed numbers back into my computer using the serial monitor. All good so far.

I have two 5m strips of LED, one colour tape attached to external power supplies, these are interfaces with the arduino with a mosfet and are plugged into ports 6 and 5 digital pins on my arduino uno. I can control my LED tape using my arduino to turn it on and off and fade in and out. This is also all good so far.

What I need help with is my missing link, how to I use the readings from my sensors to control my LEDs. I think this bit is to do with the code I am using perhaps.

I am using this code to feed my sensor readings to my arduino:

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; } }

This works fine - what I need to know now is how to say the following in code - so that my arduino now controls my LEDs.

'When sensor's 70, 71, 72 & 73 take a reading between 0-50 turn on LED strip on port 5.

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.'

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 brghtest.

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 anyone can help me with either of these queries, I would be much obliged.

Many thanks in advance,

Aphra

When sensor’s 70, 71, 72 & 73 take a reading between 0-50 turn on LED strip on port 5.

something like this …

int mode = HIGH;
for (int i=0; i<4; i++)
{
  int x = srf02[i].read();
  if ( x< 0 || x> 50) mode = LOW;
}
digitalWrite(pin5, mode);

other rules follow the same pattern

you can sum up the individual reads, average them and use that value to light/fade the leds

Hi there,

thanks for your response. I am a complete novice when it comes to code so am not entirely sure which bit of your code means what! Would you typing next to the bits of code what they refer to and which bits I change.

When I try to upload the code it comes up with this error message:

allsensorfeedback:37: error: expected unqualified-id before ‘for’
allsensorfeedback:37: error: expected constructor, destructor, or type conversion before ‘<’ token
allsensorfeedback:37: error: expected constructor, destructor, or type conversion before ‘++’ token
allsensorfeedback:42: error: expected constructor, destructor, or type conversion before ‘(’ token

Do you have any idea what this all means!!

I really appreciate your help,

Thanks,

A

I am a complete novice when it comes to code so am not entirely sure which bit of your code means what!

Best advice is to spend a few days on the tutorial and reference section of the arduino.cc site as there is a lot to learn about what is possible in the language.

don’t have SRF02’s but the code should look something like this… (not tested)

#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)
  {
    nextPrint = millis () + 1000;

    // use a for loop to minimize repeating code
    for (int i=0; i<4; i++)
    {
      Serial.print(srf02[i].read());
      Serial.print(",");
    }
    Serial.println();

    // check the values  here only [0] as example
    int mode = HIGH;
    int x = srf02[0].read();
    if (( x< 0) ||( x> 50))
    {
      mode = LOW;
    }
    digitalWrite(pin5, mode);
  }
}

Hi there,

Thanks for your response. When I add try and upload the code it comes up with this error message:

sketch_jan05b.ino: In function 'void loop()': sketch_jan05b:41: error: 'pin5' was not declared in this scope

Do you know how to fix it?

Many thanks,

Aphra

declare it as a variable somewhere at the top near other global vars..

int pin5 = 5;