Steven ChungKeming ZhangChibu EjioforJason WengJim Zhang
Published © MIT

Synergia Theremin

Music doesn't get better than this. (With this LaunchPad and a piezo buzzer at least.)

BeginnerFull instructions provided999999999999999908150356944127012110618056584002011136 days767
Synergia Theremin

Things used in this project

Story

Read more

Schematics

Breadboard

This is a possible breadboard layout for the control of multiple RGB LEDs using the Launchpad. If you use our code, the wire from the transistor for control of the red color in the LEDs will go to pin 19, the green to pin 15, and the blue to pin 14.
Each LED will (depending on if it's an anode or cathode) be connected to either power or ground, and also be connected to all three transistors. It will also be connected to three resistors going to power, one for each leg that is connected to a transistor. Each transistor will be connected to one leg of all the LEDs (the leg depends on what color the transistor is controlling), a PWM pin on the LaunchPad, and to ground.

Sensors

These sensors will be connected to the Grove Base BoosterPack, which will be connected to the TI Launchpad.

Code

Energia Code

C/C++
Energia Code
//www.elegoo.com
//2016.12.8

// Define Pins
#define BLUE 14 //Pin 14
#define GREEN 15 //Pin 15
#define RED 19 //Pin 19
#define delayTime 10
#include "Ultrasonic.h"
/* Macro Define */

#define ULTRASONIC_PIN    36             /* pin of the Ultrasonic Ranger */
#define BUZZER_PIN        39 
#define LIGHT_SENSOR      26
/* Global Variables */

Ultrasonic ultrasonic(ULTRASONIC_PIN);    /* Ultrasonic Ranger object */
int distance = 0;                         /* variable to store the distance to obstacles in front */
int tones[] = { 2551, 2273, 2024, 1915, 1700, 1519, 1432, 1275}; //set the pitches that you want
int i;
int analog_value = 0;
/* the setup() method runs once, when the sketch starts */

void setup()
{
Serial.begin(9600);
pinMode(BUZZER_PIN, OUTPUT); 
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
digitalWrite(RED, HIGH);
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, HIGH); //set an initial color to the LEDs
}

// define variables
int redValue;
int greenValue;
int blueValue;

void playTone(int tone, int duration) 
{
  for (long i = 0; i < duration * 1000L; i += tone * 2) 
  {
    digitalWrite(BUZZER_PIN, HIGH);
    delayMicroseconds(tone/5);
    digitalWrite(BUZZER_PIN, LOW);
    delayMicroseconds(tone/5);
  }
}

// main loop
void loop()
{

distance = ultrasonic.MeasureInCentimeters();   /* read the value from the sensor */  
Serial.println(distance);
    i = distance / 10;
    if (i >= 7){
      i = 7;
      }
    playTone(tones[i], 300);
    if(i == 0){
      redValue = 255; //red
      blueValue = 0;
      greenValue = 0;
      analogWrite(RED, redValue);
      analogWrite(GREEN, greenValue);
      analogWrite(BLUE, blueValue);
    }
    if(i == 1){
      redValue = 255; //orange
      blueValue = 0;
      greenValue = 130;
      analogWrite(RED, redValue);
      analogWrite(GREEN, greenValue);
      analogWrite(BLUE, blueValue);
    }
    if(i == 2){
      redValue = 255; //yellow
      blueValue = 0;
      greenValue = 255;
      analogWrite(RED, redValue);
      analogWrite(GREEN, greenValue);
      analogWrite(BLUE, blueValue);
    }
    if(i == 3){
      redValue = 0; //green
      blueValue = 0;
      greenValue = 255;
      analogWrite(RED, redValue);
      analogWrite(GREEN, greenValue);
      analogWrite(BLUE, blueValue);
    }
    if(i == 4){
      redValue = 0;
      blueValue = 250; //blue
      greenValue = 0;
      analogWrite(RED, redValue);
      analogWrite(GREEN, greenValue);
      analogWrite(BLUE, blueValue);
    }
    if(i == 5){
      redValue = 80;
      blueValue = 150; //purple
      greenValue = 0;
      analogWrite(RED, redValue);
      analogWrite(GREEN, greenValue);
      analogWrite(BLUE, blueValue);
    }
    if(i == 6){
      redValue = 255;
      blueValue = 140; //indigo
      greenValue = 0;
      analogWrite(RED, redValue);
      analogWrite(GREEN, greenValue);
      analogWrite(BLUE, blueValue);
    }
    if(i == 7){
      redValue = 250; //white
      blueValue = 250;
      greenValue = 250;
      analogWrite(RED, redValue);
      analogWrite(GREEN, greenValue);
      analogWrite(BLUE, blueValue);
    }
    analog_value = analogRead(LIGHT_SENSOR); //if it's dark, don't do anything
    while (analog_value < 800){
      delay(30);
      analog_value = analogRead(LIGHT_SENSOR);
      }
      
}

Credits

Steven Chung

Steven Chung

1 project • 0 followers
Keming Zhang

Keming Zhang

1 project • 0 followers
Chibu Ejiofor

Chibu Ejiofor

1 project • 0 followers
Jason Weng

Jason Weng

1 project • 0 followers
Jim Zhang

Jim Zhang

1 project • 0 followers

Comments