hi guys,
i'm running difficult situation.
i have solenoids , servos controlled midi notes. far works perfectly.
here's explanation of current code below.
1) if receives note on, listen note is
2) each note call specific function
3) note off, stop function
i'm running difficult situation.
i have solenoids , servos controlled midi notes. far works perfectly.
here's explanation of current code below.
1) if receives note on, listen note is
2) each note call specific function
3) note off, stop function
code: [select]
#include <varspeedservo.h>
byte type = 0;
byte incomingbyte;
byte note;
byte velocity;
int chan = 1; //specify midi channel we're listing to
byte boucle = 0; // boucle
int action = 2; //0 =note off ; 1=note on ; 2= null
int currenttime;
int previoustime;
const int lownote = 60; //what's first note? 36 c1 in ableton
varspeedservo servoe; // create servo object control servo open circuit
varspeedservo servos; // create servo object control servo close circuit
const byte solenoidspin[] = {22, 23, 24, 25, 26, 27, 28, 29};
const byte number_of_solenoids = sizeof(solenoidspin);
unsigned long starttimes[number_of_solenoids];
unsigned long periods[] = {80, 60, 100, 80, 60, 40, 110, 90};
// loop function runs on , on again forever
void setup() {
serial.begin(38400);
for (int p = 0; p < number_of_solenoids; p++)
{
pinmode(solenoidspin[p], output);
}
servoe.attach(30);
servos.attach(31);
//setup our outputs
pinmode(22, output); // 1
digitalwrite (22, low);
pinmode(23, output);
digitalwrite (23, low);
pinmode(24, output); // 2
digitalwrite (24, low);
pinmode(25, output);
digitalwrite (25, low);
pinmode(26, output); // 3
digitalwrite (26, low);
pinmode(27, output);
digitalwrite (27, low);
pinmode(28, output); // 4
digitalwrite (28, low);
pinmode(29, output);
digitalwrite (29, low);
}
void vibe20 () {
servoe.write(90, 0, true);
servos.write(55, 0);
while ( true )
{
static unsigned long previoustime = 0;
currenttime = millis();
if (currenttime - previoustime >= 20)
{
digitalwrite (22, !digitalread(22));
digitalwrite (23, !digitalread(23));
digitalwrite (24, !digitalread(24));
digitalwrite (25, !digitalread(25));
digitalwrite (26, !digitalread(26));
digitalwrite (27, !digitalread(27));
digitalwrite (28, !digitalread(28));
digitalwrite (29, !digitalread(29));
if (currenttime < previoustime) // check rollover
previoustime = 0;
previoustime += 20; // increment previous time delay factor "20"
}
if (serial.available() > 0)
{
incomingbyte = serial.read();
if (incomingbyte == lownote)
break; // if incomingbyte equal chan+127
}
}
digitalwrite (22, low);
digitalwrite (23, low);
digitalwrite (24, low);
digitalwrite (25, low);
digitalwrite (26, low);
digitalwrite (27, low);
digitalwrite (28, low);
digitalwrite (29, low);
}
void vibe25 () {
servoe.write(90, 0, true);
servos.write(55, 0);
while ( true )
{
static unsigned long previoustime = 0;
currenttime = millis();
if (currenttime - previoustime >= 25)
{
digitalwrite (22, !digitalread(22));
digitalwrite (23, !digitalread(23));
digitalwrite (24, !digitalread(24));
digitalwrite (25, !digitalread(25));
digitalwrite (26, !digitalread(26));
digitalwrite (27, !digitalread(27));
digitalwrite (28, !digitalread(28));
digitalwrite (29, !digitalread(29));
if (currenttime < previoustime) // check rollover
previoustime = 0;
previoustime += 25; // increment previous time delay factor "25"
}
if (serial.available() > 0)
{
incomingbyte = serial.read();
if (incomingbyte == lownote + 1)
break; // if incomingbyte equal 12
}
}
digitalwrite (22, low);
digitalwrite (23, low);
digitalwrite (24, low);
digitalwrite (25, low);
digitalwrite (26, low);
digitalwrite (27, low);
digitalwrite (28, low);
digitalwrite (29, low);
}
void vibe30 () {
servoe.write(90, 0, true);
servos.write(85, 0);
while ( true )
{
static unsigned long previoustime = 0;
currenttime = millis();
if (currenttime - previoustime >= 30)
{
digitalwrite (22, !digitalread(22));
digitalwrite (23, !digitalread(23));
digitalwrite (24, !digitalread(24));
digitalwrite (25, !digitalread(25));
digitalwrite (26, !digitalread(26));
digitalwrite (27, !digitalread(27));
digitalwrite (28, !digitalread(28));
digitalwrite (29, !digitalread(29));
if (currenttime < previoustime) // check rollover
previoustime = 0;
previoustime += 30; // increment previous time delay factor "30"
}
if (serial.available() > 0)
{
incomingbyte = serial.read();
if (incomingbyte == lownote + 2)
break; // if incomingbyte equal 12
}
}
digitalwrite (22, low);
digitalwrite (23, low);
digitalwrite (24, low);
digitalwrite (25, low);
digitalwrite (26, low);
digitalwrite (27, low);
digitalwrite (28, low);
digitalwrite (29, low);
}
void vibe35 () {
servoe.write(90, 0, true);
servos.write(55, 0);
while ( true )
{
static unsigned long previoustime = 0;
currenttime = millis();
if (currenttime - previoustime >= 35)
{
digitalwrite (22, !digitalread(22));
digitalwrite (23, !digitalread(23));
digitalwrite (24, !digitalread(24));
digitalwrite (25, !digitalread(25));
digitalwrite (26, !digitalread(26));
digitalwrite (27, !digitalread(27));
digitalwrite (28, !digitalread(28));
digitalwrite (29, !digitalread(29));
if (currenttime < previoustime) // check rollover
previoustime = 0;
previoustime += 35; // increment previous time delay factor "35"
}
if (serial.available() > 0)
{
incomingbyte = serial.read();
if (incomingbyte == lownote + 3)
break; // if incomingbyte equal 12
}
}
digitalwrite (22, low);
digitalwrite (23, low);
digitalwrite (24, low);
digitalwrite (25, low);
digitalwrite (26, low);
digitalwrite (27, low);
digitalwrite (28, low);
digitalwrite (29, low);
}
void micro100 () {
servoe.write (40, 0, true);
servos.write (90, 0);
digitalwrite (22, low);
digitalwrite (23, low);
digitalwrite (24, low);
digitalwrite (25, low);
digitalwrite (26, low);
digitalwrite (27, low);
digitalwrite (28, low);
digitalwrite (29, low);
while (true)
{
for (int p = 0; p < number_of_solenoids; p++)
{
unsigned long currenttime = millis();
if (currenttime - starttimes[p] >= periods[p])
{
digitalwrite(solenoidspin[p], !digitalread(solenoidspin[p]));
starttimes[p] = currenttime;
}
}
if (serial.available() > 0)
{
incomingbyte = serial.read();
if (incomingbyte == lownote + 21)
break; // if incomingbyte equal 12
}
}
digitalwrite (22, low);
digitalwrite (23, low);
digitalwrite (24, low);
digitalwrite (25, low);
digitalwrite (26, low);
digitalwrite (27, low);
digitalwrite (28, low);
digitalwrite (29, low);
}
void loop () {
if (serial.available() > 0) {
// read incoming byte:
incomingbyte = serial.read();
// wait status-byte, channel 1, note on or off
if (incomingbyte == 143 + chan) { // note on message starting starting
action = 1;
}
if (incomingbyte == 127 + chan) { // note off message starting
action = 0;
}
if ( (action == 0)/*&&(note==0)*/ ) { // if received "note off", wait note (databyte)
note = incomingbyte;
}
if ( (action == 1)/*&&(note==0)*/ ) { // if received "note on", wait note (databyte)
note = incomingbyte;
moveservo(note);
}
}
}
void moveservo(byte note) { // call function based on note
switch (note) {
case lownote:
vibe20 ();
break;
case lownote+1:
vibe25 ();
break;
case lownote+2:
vibe30 ();
break;
case lownote+3:
micro100 ();
break;
}
}
i'm trying add pressure sensor indicate me pressure flow in circuit. according value i'll obtain, d'like "servoe" controls water flow @ beginning of circuit open or close according value of sensor.
i map such (random value moment):
sensor value obtained in mbar: on or equal 973 = "servoe" 70 degrees
sensor value obtained in mbar: on or equal 1500>= "servoe" 80 degrees
sensor value obtained in mbar: on or equal 2000>= "servoe" 90 degrees
therefore d'like achieve creating function "void pressuresensor" being activated midi note lownote+4 other functions above. know how similar others functions above.
1- every time function called, solenoids turn high , low in 1 second.
2- sensor measure value.
3- if value on or equal x "servoe" changes 70 degrees in other functions above. if value on or equal z "servoe" changes 80 degrees , forth.
i guess should try implement "if" function wonder how can change "servoe" angle in functions (from lownote lownote+3) according sensor value obtained function pressuresensor?
another idea i'm having remove "servoe" functions , put in void loop, before calling each midi note, check previous sensor state?
btw, here's pressure sensor code i'm using , sensor freescale mpx5700ap.
finally, last issue i'm having because i'm using midi note communicate arduino. i'm using hairless software uses arduino serial received midi note. therefore won't able read sensor value using serial monitor debug code.
if me in finding right way of doing pseudo code or advices gladly appreciate
thanks lot guys.
i map such (random value moment):
sensor value obtained in mbar: on or equal 973 = "servoe" 70 degrees
sensor value obtained in mbar: on or equal 1500>= "servoe" 80 degrees
sensor value obtained in mbar: on or equal 2000>= "servoe" 90 degrees
therefore d'like achieve creating function "void pressuresensor" being activated midi note lownote+4 other functions above. know how similar others functions above.
1- every time function called, solenoids turn high , low in 1 second.
2- sensor measure value.
3- if value on or equal x "servoe" changes 70 degrees in other functions above. if value on or equal z "servoe" changes 80 degrees , forth.
i guess should try implement "if" function wonder how can change "servoe" angle in functions (from lownote lownote+3) according sensor value obtained function pressuresensor?
another idea i'm having remove "servoe" functions , put in void loop, before calling each midi note, check previous sensor state?
btw, here's pressure sensor code i'm using , sensor freescale mpx5700ap.
code: [select]
#include <varspeedservo.h>
#define adc_honeywell 0 // arduino analog pin
const float null = 0.50; // null vdc; datasheet page 32
const float sensitivity = 266.6; // sensitivity mv/psi; mpx5700ap
varspeedservo servoe;
serial.begin(9600);
}
// loop function runs on , on again forever
void loop() {
serial.print("p: ");
serial.print(getpressure());
serial.println("mbar g");
}
float getpressure(void) {
float pressurepsi,pressurembar,pressurevdc;
int pressure;
pressure = analogread(adc_honeywell);
pressurevdc = (float)pressure * 0.0048828125; // (5/1024 = 0.0048828125)
pressurevdc = pressurevdc - null;
pressurepsi = pressurevdc / sensitivity * 1000;
pressurembar = pressurepsi * 68.948;
return pressurembar;
}
finally, last issue i'm having because i'm using midi note communicate arduino. i'm using hairless software uses arduino serial received midi note. therefore won't able read sensor value using serial monitor debug code.
if me in finding right way of doing pseudo code or advices gladly appreciate
thanks lot guys.
Arduino Forum > Using Arduino > Programming Questions > Pressure sensor and If function
arduino
Comments
Post a Comment