Initially we planned to program the Penta-Tone to function in two modes out-of-the-box. First mode is playing music – each end unit represents a tone and a sound and stepping on it will produce that tone and sound. The second mode is playing a game.
We completed the first mode by now and we will add the second mode sometime in the near future.
The End Unit Code:
Each end unit is programmed to wait for a “step” event (load sensor is under pressure) and a “release” event (load sensor sense no pressure).
// read the voltage from the voltage divider // (sensor plus resistor) sensor = analogRead(0)
In the case of a “step” event the end unit tries to send an RF message that includes the tone it represents, and “ON” command and if successfull – light the LED strip
payload_t payload = { ON, this_node_note }; bool ok = network.write(header,&payload,sizeof(payload)); ... analogWrite(GREENPIN, 200); analogWrite(BLUEPIN, 50);
In the case of a “step” event the end unit tries to send an RF message that includes the tone it represents, and “OFF” command
payload_t payload = {OFF, this_node_note }; bool ok = network.write(header,&payload,sizeof(payload)); ... analogWrite(GREENPIN, 0); analogWrite(BLUEPIN, 0);
The Controller Code:
The Controller listens for RF messages and as a message arrives it turns it to a MIDI message and sends it through a Serial port:
// Is there anything ready for us? while ( network.available() ) { RF24NetworkHeader header; payload_t payload; network.read(header,&payload,sizeof(payload)); note = payload.note; currentCommand = payload.command; if (payload.command == true){ // send note ON command MIDInoteON(note, vel); } if (currentCommand == false) { // send note OFF command //turn note off MIDInoteOFF(note, 0); } } }
Controller code: ControlBox
End Unit code: PlayingBox
(note: for each End Unit Id and Note variables should be adjusted, and LED colors can be changed)
Parts of the code are based on code written by: