Hi guys, I'm fairly new to programming this, so I needed a bit of help with switching octaves up and down using two laser beams out of the current nine beams, in my Laser Harp. I'm sure most of you guru's can understand how it works by looking through the sketch, but if not then let me know.
I've deleted most of the lines for this post, and only left the two beams in the sketch that I need help with.
Here's a link to the 'Ible I got the majority of the code from: http://www.instructables.com/id/Frameless-Laser-Harp/?ALLSTEPS
// Shane Rienks - Laser Harp with 9 "strings" as of right now - 2/11/14 - BETA 2 (Original sketch from Pushan Panda's Instructible: http://www.instructables.com/id/Frameless-Laser-Harp/?ALLSTEPS )
int LaserState = LOW; // The variable that stores the state of the laser beam.
int sensor = 10; // Change this value to calibrate your harp's sensor.
int delaylaser = 5; // If you increase this, the laser will be brighter, but the harp will be less fluid.
int delaymotor = 3; // This variable affects the speed, and fluidity of the harp.
int LaserPin = 7; // Tell the arduino that the laser is on digital pin 7.
int motorPin1 = 11; // Use these names for the pin numbers.
int motorPin2 = 10;
int motorPin3 = 9;
int motorPin4 = 8;
int note9 = 0x61;
int note8 = 0x63;
int note7 = 0x64;
int note6 = 0x66;
int note5 = 0x68;
int note4 = 0x70;
int note3 = 0x71;
int note2 = 0x40;
int note1 = 0x47;
int a, b, c, d, e, f, g, h, i = 0; // Initiating the note status markers.
void setup()
{
pinMode(11, OUTPUT); // Setup for the motor.
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(LaserPin, OUTPUT); // Setup for the laser TTL.
pinMode(13, OUTPUT); // Setup for status led.
Serial.begin(31250); // Start a serial communication channel for MIDI control.
}
void noteOn(int cmd, int pitch, int velocity) // Function to play the notes.
{
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}
void loop()
{
digitalWrite(LaserPin, HIGH); // This is beam 8.
delay(delaylaser);
if( (analogRead(0) > sensor ) && (h == 0) )
{
digitalWrite(13, HIGH);
noteOn(0x90, note8, 0x7F);
h++;
}
else if(analogRead(0) < sensor )
{
digitalWrite(13, LOW);
noteOn(0x90, note8, 0x00);
h = 0;
}
digitalWrite(LaserPin, LOW);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(delaymotor);
digitalWrite(LaserPin, HIGH); // This is beam 9.
delay(delaylaser);
if( (analogRead(0) > sensor ) && (i == 0) )
{
digitalWrite(13, HIGH);
noteOn(0x90, note9, 0x7F);
i++;
}
else if(analogRead(0) < sensor )
{
digitalWrite(13, LOW);
noteOn(0x90, note9, 0x00);
i = 0;
}
digitalWrite(LaserPin, LOW);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(delaymotor);
digitalWrite(LaserPin, HIGH); // This is beam 8.
delay(delaylaser);
if( (analogRead(0) > sensor ) && (h == 0) )
{
digitalWrite(13, HIGH);
noteOn(0x90, note8, 0x7F);
h++;
}
else if(analogRead(0) < sensor )
{
digitalWrite(13, LOW);
noteOn(0x90, note8, 0x00);
h = 0;
}
digitalWrite(LaserPin, LOW);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(delaymotor);
Shane