Week Nine

Resister calculations/RGB values



Processing Script:
Setup libraries, inputs, and output message:

//Import libraries
import processing.serial.*;
import promidi.*;
Serial myPort;
MidiIO midiIO;
int message=0;  
void setup()
{
  myPort = new Serial(this, "COM7", 9600);
  midiIO = MidiIO.getInstance(this);
  midiIO.printDevices();   //Line that prints I/O devices in console
  midiIO.openInput(1,0);  //Receive input from Virtual MIDI Ports
}

Check for pitch of incoming note, and send message from 1-12 to Arduino


void noteOn(Note note, int deviceNum, int midiChan) /

{
  int vel = note.getVelocity();
  int pitch = note.getPitch();
  int dur = note.getNoteLength();
  switch(pitch)
  {
    case 36:
    case 48:
    case 60:
    case 72:
      message = 1;
    ...
  }
  myPort.write(message);
}


Arduino Script:
set up pins and RGB values for each of the 12 colors


 int val;
 int pins[] = {10,11,13};
 int red[] ={236,10,10};
...

Set pins as outputs, initiate serial communication at 9600 bps


 void setup()
{
   for(int i=0; i<3; i++){
   pinMode(pins[i], OUTPUT);
   }
   Serial.begin(9600);
 }


Receive message from Processing, and send out corresponding color via PWM pins

 void loop() {
 if (Serial.available())
 {
 val = Serial.read();  
  switch(val)
  {
    case 1:
      analogWrite(pins[0],red[0]);
      analogWrite(pins[1],red[1]);
      analogWrite(pins[2],red[2]);
      break;
      "   "
    default:
      resetLEDs();
      break;
  }
 }
 }

Loop to reset LEDS when no inputs are detected

 void resetLEDs(){
  for(int i=0; i<8; i++){
   digitalWrite(pins[i],LOW);
   analogWrite(pins[i],0);
  }
 }




No comments:

Post a Comment