INITIAL TESTING

FIRST TEST OF THE HC-SR04 SENSOR

This was my first use of a distance sensor with Touchdesigner. It works fairly well passing data via the serial port. However the sensor was not particularly accurate and readings were irratic, this was resolved by using the ‘newPing’ Arduino library (https://www.arduino.cc/reference/en/libraries/newping/). This gave me much more acculturate, stable readings. However there would be issues with this down the line.

TESTING LFO READINGS

After properly testing the LFO outputs they were actually outputting around 3v p-p so were fine without pulldown resistors. However the arduino can’t read negative voltages, and while not an issue for squarewaves, you lose the negative half of the triangle. This could be solved with a RC circuit to scale the voltages so 2.5v is the new zero. This is beyond my current skill set and could risk overloading the board. For my current purposes uni-polar waves are fine.

DISTANCE SENSOR AND LED INTERACTION TEST

I first intended to have my LEDs reacting to the distance sensor data in the same way my visuals and audio would. I soon realised however that aside from looking cool this was pretty pointless. Having the LEDs mirror the synths LFO would be far more useful as the current LFO indicator on the synth is a 1mm tiny LED. This gives me useful visual feedback while performing, and it looks cool.

The code from this testing is below.

#include <FastLED.h>
#include <NewPing.h>

    #define NUM_LEDS1 8
    #define NUM_LEDS2 8
    #define DATA_PIN1 10 
    #define DATA_PIN2 11
    CRGB leds1[NUM_LEDS1];
    CRGB leds2[NUM_LEDS2];

#define TRIGGER_PIN  3
#define ECHO_PIN     2
#define MAX_DISTANCE 60
#define NOTE_PIN 13

  NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
float duration1;
float distance;
float tempVal;

float sensUp;
float brightness;

float pitch;

int iterations = 5;


// For mirroring strips, all the "special" stuff happens just in setup.  We
// just addLeds multiple times, once for each strip
void setup() {


  Serial.begin (9600);
  pinMode(NOTE_PIN, OUTPUT);
  
FastLED.addLeds<NEOPIXEL, DATA_PIN1>(leds1, NUM_LEDS1);
FastLED.addLeds<NEOPIXEL, DATA_PIN2>(leds2, NUM_LEDS2);



}


void loop() {

   duration1 = sonar.ping_median(iterations);
  
  // Determine distance from duration
  // Use 343 metres per second as speed of sound
  
  distance = (duration1 / 2) * 0.0343;

  // Send results to Serial Monitor
  Serial.print("Distance = ");
  if (distance >= 60 || distance <= 2) {
    Serial.println(0);
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
    delay(10);
  }
  
 
  sensUp = map(distance, 0, 60 , 0, 20);
  brightness = map(distance, 0, 60 , 255, 0);
  pitch = map(distance, 0, 60 , 0, 1023);
  
    if ( sensUp > 0)  {fill_solid( &(leds1[0]), NUM_LEDS1, CRGB::Blue);
     FastLED.setBrightness(brightness);
     FastLED.show();
    }   
    else if (sensUp <= 0) {fill_solid( &(leds1[0]), NUM_LEDS1, CRGB::Black);
     FastLED.show();
      }

          if ( sensUp > 0)  {fill_solid( &(leds2[0]), NUM_LEDS2, CRGB::Green);
     FastLED.setBrightness(brightness);
     FastLED.show();
    }   
    else if (sensUp <= 0) {fill_solid( &(leds2[0]), NUM_LEDS2, CRGB::Black);
     FastLED.show();
      }

      analogWrite(NOTE_PIN, pitch);
      delay(10);
}

Leave a comment

Your email address will not be published. Required fields are marked *