broncode pseudo theremin
7 berichten
• Pagina 1 van 1
broncode pseudo theremin
Beste allemaal ,
Arduino is compleet nieuw voor mij maar vol vertrouwen ben ik met mijn eerste midi projectje begonnen .
Arduino mega 2560 met 2 ir sensors een paar draadjes , source code downloaden , uploaden en klaar .
Dus niet ,,,,,,,,
//Pseudo MIDI theremin for Arduino v1.0
//Rein Velt - Theo's Mechanic Ape - http://mechanicape.com
//15 january 2012
#include
NewSoftSerial mySerial(2, 3); //Soft TX on 3, we don't use RX in this code
int note=0;
int instrument=0;
int volume=0;
void setup() {
delay(3000);
instrument=117;
Serial.begin(57600);
//Setup soft serial for MIDI control
mySerial.begin(31250);
//channel 0
talkMIDI(0xB0, 0x07, 127); //0xB0 is channel message, set channel volume to near max (127)
talkMIDI(0xB0, 0,0x78); //Select the bank of melodic sounds
//Set the instrument for channel 0
talkMIDI(0xC0, instrument, 0); //Set instrument number. 0xC0 is a 1 data byte command
}
void loop() {
int oldnote=note;
note=getSensorValue(0); //get value from first sensor (port A0)
volume=getSensorValue(1); //get value from second sensor (port A1)
noteOn(0,note,volume); //play it
}
//Send a MIDI note-on message. Like pressing a piano key
//channel ranges from 0-15
void noteOn(byte channel, byte note, byte attack_velocity)
{
talkMIDI( (0x90 | channel), note, attack_velocity);
}
//Send a MIDI note-off message. Like releasing a piano key
void noteOff(byte channel, byte note, byte release_velocity)
{
talkMIDI( (0x80 | channel), note, release_velocity);
}
//Plays a MIDI note. Doesn't check to see that cmd is greater than 127, or that data values are less than 127
void talkMIDI(byte cmd, byte data1, byte data2)
{
mySerial.print(cmd, BYTE);
mySerial.print(data1, BYTE);
//Some commands only have one data byte. All cmds less than 0xBn have 2 data bytes
//(sort of: http://253.ccarh.org/handout/midiprotocol/)
if( (cmd & 0xF0) <= 0xB0)
mySerial.print(data2, BYTE);
}
//read converted value from the specified sensor
int getSensorValue(int analogPort)
{
int intval=0;
int result=0;
intval=analogRead(analogPort);
delay(40);
float volts=(intval)*0.0048828125;
int distance = round(65*pow(volts, -1.10));
if (distance>0 and distance<150)
{
result=map(distance,0,150,0,127);
}
return result;
}
cygiconv-2.dll.ino:6:10: error: #include expects "FILENAME" or <FILENAME>
cygiconv-2.dll.ino:7: error: 'NewSoftSerial' does not name a type
cygiconv-2.dll.ino: In function 'void setup()':
cygiconv-2.dll.ino:21: error: 'mySerial' was not declared in this scope
cygiconv-2.dll.ino: In function 'void talkMIDI(byte, byte, byte)':
cygiconv-2.dll.ino:55: error: 'mySerial' was not declared in this scope
cygiconv-2.dll.ino:55: error: 'BYTE' was not declared in this scope
Best veel ´errors ´ wie wil en kan mij helpen ,
Ik ben de programma taal aan het leren maar ik heb een zetje nodig .
alvast bedankt voor jullie reactive
vrgr Willem
Arduino is compleet nieuw voor mij maar vol vertrouwen ben ik met mijn eerste midi projectje begonnen .
Arduino mega 2560 met 2 ir sensors een paar draadjes , source code downloaden , uploaden en klaar .
Dus niet ,,,,,,,,
//Pseudo MIDI theremin for Arduino v1.0
//Rein Velt - Theo's Mechanic Ape - http://mechanicape.com
//15 january 2012
#include
NewSoftSerial mySerial(2, 3); //Soft TX on 3, we don't use RX in this code
int note=0;
int instrument=0;
int volume=0;
void setup() {
delay(3000);
instrument=117;
Serial.begin(57600);
//Setup soft serial for MIDI control
mySerial.begin(31250);
//channel 0
talkMIDI(0xB0, 0x07, 127); //0xB0 is channel message, set channel volume to near max (127)
talkMIDI(0xB0, 0,0x78); //Select the bank of melodic sounds
//Set the instrument for channel 0
talkMIDI(0xC0, instrument, 0); //Set instrument number. 0xC0 is a 1 data byte command
}
void loop() {
int oldnote=note;
note=getSensorValue(0); //get value from first sensor (port A0)
volume=getSensorValue(1); //get value from second sensor (port A1)
noteOn(0,note,volume); //play it
}
//Send a MIDI note-on message. Like pressing a piano key
//channel ranges from 0-15
void noteOn(byte channel, byte note, byte attack_velocity)
{
talkMIDI( (0x90 | channel), note, attack_velocity);
}
//Send a MIDI note-off message. Like releasing a piano key
void noteOff(byte channel, byte note, byte release_velocity)
{
talkMIDI( (0x80 | channel), note, release_velocity);
}
//Plays a MIDI note. Doesn't check to see that cmd is greater than 127, or that data values are less than 127
void talkMIDI(byte cmd, byte data1, byte data2)
{
mySerial.print(cmd, BYTE);
mySerial.print(data1, BYTE);
//Some commands only have one data byte. All cmds less than 0xBn have 2 data bytes
//(sort of: http://253.ccarh.org/handout/midiprotocol/)
if( (cmd & 0xF0) <= 0xB0)
mySerial.print(data2, BYTE);
}
//read converted value from the specified sensor
int getSensorValue(int analogPort)
{
int intval=0;
int result=0;
intval=analogRead(analogPort);
delay(40);
float volts=(intval)*0.0048828125;
int distance = round(65*pow(volts, -1.10));
if (distance>0 and distance<150)
{
result=map(distance,0,150,0,127);
}
return result;
}
cygiconv-2.dll.ino:6:10: error: #include expects "FILENAME" or <FILENAME>
cygiconv-2.dll.ino:7: error: 'NewSoftSerial' does not name a type
cygiconv-2.dll.ino: In function 'void setup()':
cygiconv-2.dll.ino:21: error: 'mySerial' was not declared in this scope
cygiconv-2.dll.ino: In function 'void talkMIDI(byte, byte, byte)':
cygiconv-2.dll.ino:55: error: 'mySerial' was not declared in this scope
cygiconv-2.dll.ino:55: error: 'BYTE' was not declared in this scope
Best veel ´errors ´ wie wil en kan mij helpen ,
Ik ben de programma taal aan het leren maar ik heb een zetje nodig .
alvast bedankt voor jullie reactive
vrgr Willem
Advertisement
Re: broncode pseudo theremin
En heb je eerst de NewSoftSerial library geïnstalleerd?
Arduinows!
Why do computer programmers confuse Halloween with Christmas? Because Oct 31 = Dec 25
I got 01100011 problems but a bit ain't 00000001
Why do computer programmers confuse Halloween with Christmas? Because Oct 31 = Dec 25
I got 01100011 problems but a bit ain't 00000001
Re: broncode pseudo theremin
Beste Allemaal (Rudi)
Ik ben heerlijk aan het googlen gegaan en vond het volgende .....
Ik heb ' NewSoftSerial ' vervangen door ' SoftwareSerial ' ,
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //Soft TX on 3, we don't use RX in this code
Nu heb ik nog twee errors over , nl
nogff.dll.ino: In function 'void talkMIDI(byte, byte, byte)':
nogff.dll.ino:55: error: 'BYTE' was not declared in this scope
zie complete source code
is er iemand die mij kan helpen ???
alvast bedankt
vrgr Willem
Ik ben heerlijk aan het googlen gegaan en vond het volgende .....
Ik heb ' NewSoftSerial ' vervangen door ' SoftwareSerial ' ,
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //Soft TX on 3, we don't use RX in this code
Nu heb ik nog twee errors over , nl
nogff.dll.ino: In function 'void talkMIDI(byte, byte, byte)':
nogff.dll.ino:55: error: 'BYTE' was not declared in this scope
zie complete source code
is er iemand die mij kan helpen ???
alvast bedankt
vrgr Willem
- nicoverduin
- Berichten: 5043
- Geregistreerd: 13 Mei 2013, 20:57
- Woonplaats: Heemskerk
Re: broncode pseudo theremin
BYTE wordt al heel lang niet meer ondersteund. In feite is het niet meer als een formatter dus hoe je het getal zien wilt. Mogelijkheden:
- HEX dan wordt het als hexadecimaal getoond
- DEC dan wordt het als decimaal getoond.
Dit zijn de meest relevante mogelijkheden
- HEX dan wordt het als hexadecimaal getoond
- DEC dan wordt het als decimaal getoond.
Dit zijn de meest relevante mogelijkheden
Re: broncode pseudo theremin
Beste Nico ,
als ik het goed begrijp moet ik alle byte(s) / BYTE(s) vervangen door 'HEX' of 'DEC' .
als ik het goed begrijp moet ik alle byte(s) / BYTE(s) vervangen door 'HEX' of 'DEC' .
- nicoverduin
- Berichten: 5043
- Geregistreerd: 13 Mei 2013, 20:57
- Woonplaats: Heemskerk
Re: broncode pseudo theremin
Alleen de hoofdletter BYTE niet die in kleine letters dat is iets anders.
Re: broncode pseudo theremin
Nico en Rudi ,
heel erg bedankt voor jullie support ,
geen foutmeldingen meer , vanavond uploaden ...........
vrgr Willem
heel erg bedankt voor jullie support ,
geen foutmeldingen meer , vanavond uploaden ...........
vrgr Willem
7 berichten
• Pagina 1 van 1
Wie is er online?
Gebruikers in dit forum: Geen geregistreerde gebruikers en 21 gasten