Posted on and Updated on

Intro to Physical Computing ⁄ Week 12 ⁄ Final

Synesthesia VR

Synopsis

Escape into another world.

Synesthesia VR is a device that enables you to experience your surroundings in a new and exciting way. By immersing yourself in this isolated virtual space, you are liberated from the shackles of order and illusions of comprehension, and freed into the higher realm of pure data.

The headset equips you with your very own prosthetic aural and visual sensory inputs which exchange data before feeding into your native senses, in order to ensure complete lack of comprehension of, and thus disconnection from our mundane reality.

Parts

Code

The final Arduino code is below. It uses the Goldelox 4D library (Goldelox is the name of the graphics processor for the LCD displays used, this library implements what the 4D company calls “4DGL” which makes interfacing with the displays very easy), as well as a dedicated library for Sparkfun’s SFE_ISL29125 RGB light sensor. Code for the sound detector can be referenced from here.

/*
 * __________//______//______//____/////____/////__
 * _______////____///__///__//__________//__________
 * ____//____//__///////__//__________//__________
 * ___//////__//__/__//__//__________//__________
 * __//____//__//______//____/////____/////__
 * ___________________________________________________________
 * __________ Copyright (c) 2016 Andrew McCausland __________
 * ________________ <andrewmccausland.net> _________________
 * ________________________________________________________
 * 
 * To upload new code:
 * 1. Disconnect main display (the one that's directly hooked to RX/TX)
 * 2. Disconnect TX connection to display 2
 * 3. Upload
 * 4. Reconnect main display, wait for it to begin visualization
 * 5. Reconnect TX connection to display 2.
 * 
 */

// ------------------------------ visual output (display stuff)
#include "Goldelox_Serial_4DLib.h"
#include "Goldelox_const4D.h"
#define DisplaySerial Serial // The compiler will replace any mention of DisplaySerial with the value Serial 
Goldelox_Serial_4DLib Display(&DisplaySerial);
int width = 127;
int height = 127;
int visOutSwitch = 0;

// ------------------------------ sound input stuff
#define PIN_GATE_IN 2
#define IRQ_GATE_IN  3
#define PIN_LED_OUT 13
#define PIN_ANALOG_IN A0

// ----------------------------- visual input (rgb sensor)

#include <Wire.h>
#include "SFE_ISL29125.h"
SFE_ISL29125 RGB_sensor;

// ----------------------------- sound output

int auxOutPin = 6;
int auxOutSwitch = 0;

void setup() {
  
  // ------------------------------ visual output (displays)
  Display.Callback4D = mycallback;
  Display.TimeLimit4D = 5000;
  DisplaySerial.begin(9600);

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  
  delay (10000); //back up buffer time to let the display start up

  Display.gfx_ScreenMode(LANDSCAPE);

  // ------------------------------ sound input
  pinMode(PIN_LED_OUT, OUTPUT);
  pinMode(PIN_GATE_IN, INPUT);
  attachInterrupt(IRQ_GATE_IN, soundISR, CHANGE);

  // ------------------------------ visual input (rgb sensor)
  
  RGB_sensor.init();
}

void loop() {

  // ------------------------------ for sound input
  int value = analogRead(PIN_ANALOG_IN);

  // ------------------------------ for visual output (display)

  unsigned int blueColors[4] = {MIDNIGHTBLUE,BLUE,DEEPSKYBLUE,LIGHTBLUE};
  unsigned int greenColors[4] = {DARKGREEN,GREEN,GREENYELLOW,LIGHTGREEN};
  unsigned int redColors[4] = {DARKRED,CRIMSON,RED,LIGHTCORAL};
  int brightness = map(value, 0, 600, 0, 3);

  if(value > 80 && value <= 100){
    
      Display.gfx_RectangleFilled(0, 0, width, height, blueColors[brightness]);
      visOutSwitch = 0;
      
  } else if(value > 100 && value <= 200){
    
    if(visOutSwitch == 0){
      Display.gfx_RectangleFilled(0, 0, width, height, blueColors[brightness]);
      visOutSwitch++;
    } else {
      Display.gfx_RectangleFilled(0, 0, width, height, greenColors[brightness]);
      visOutSwitch = 0;
    }
    
  } else if(value > 200 && value <= 600){
    
    if(visOutSwitch == 0){
      Display.gfx_RectangleFilled(0, 0, width, height, blueColors[brightness]);
      visOutSwitch++;
    } else if(visOutSwitch == 1){
      Display.gfx_RectangleFilled(0, 0, width, height, greenColors[brightness]);
      visOutSwitch++;
    } else {
      Display.gfx_RectangleFilled(0, 0, width, height, redColors[brightness]);
      visOutSwitch = 0;
    }
    
  } else if(value > 600){
      Display.gfx_RectangleFilled(0, 0, width, height, WHITE);
      visOutSwitch = 0;
  }

  if(value > 5){
    Display.gfx_Cls(); //clear the screen
  }


  // ------------------------------ for visual input (rgb sensor)
  unsigned int red = RGB_sensor.readRed();
  unsigned int green = RGB_sensor.readGreen();
  unsigned int blue = RGB_sensor.readBlue();

  // ----------------------------- for sound output
  if(auxOutSwitch == 0){
    tone(auxOutPin, red,200);
    auxOutSwitch++;
  } else if (auxOutSwitch == 1){
    tone(auxOutPin, green,200);
    auxOutSwitch++;
  } else {
    tone(auxOutPin, blue,200);
    auxOutSwitch = 0;
  }

}

// ------------------------------ for display
void mycallback(int ErrCode, unsigned char Errorbyte) {
  // Pin 13 has an LED connected on most Arduino boards. Just give it a name
  int led = 13;
  pinMode(led, OUTPUT);
  while(1){
    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
    digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  }
}

// ------------------------------ for sound input
void soundISR() {
  int pin_val;

  pin_val = digitalRead(PIN_GATE_IN);
  digitalWrite(PIN_LED_OUT, pin_val);   
}

Leave a Reply

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