arduino fonctionne avec 1 port = 8 entrees

This commit is contained in:
Christophe 2019-10-04 21:26:18 +02:00
parent 733ca09efc
commit bb6e9934f6

View File

@ -17,65 +17,85 @@
*/ */
/*
bool EtatEntree24 = HIGH ;
bool VarSuivi24 = HIGH ;
bool EtatEntree25 = HIGH ;
bool VarSuivi25 = HIGH ;
bool EtatEntree26 = HIGH ;
bool VarSuivi26 = HIGH ;
bool EtatEntree27 = HIGH ;
bool VarSuivi27 = HIGH ;
bool EtatEntree28 = HIGH ;
bool VarSuivi28 = HIGH ;
bool EtatEntree29 = HIGH ;
bool VarSuivi29 = HIGH ;
bool EtatEntree22 = HIGH ;
bool VarSuivi22 = HIGH ;
bool EtatEntree23 = HIGH ;
bool VarSuivi23 = HIGH ; */
const byte Masque1 = B00000001 ;
const byte Masque2 = B00000010 ;
const byte Masque4 = B00000100 ;
const byte Masque8 = B00001000 ;
const byte Masque16 = B00010000 ;
const byte Masque32 = B00100000 ;
const byte Masque64 = B01000000 ;
const byte Masque128 = B10000000 ;
char PortA = 0 ; const int Masque1 = B00000001 ;
const int Masque2 = B00000010 ;
const int Masque4 = B00000100 ;
const int Masque8 = B00001000 ;
const int Masque16 = B00010000 ;
const int Masque32 = B00100000 ;
const int Masque64 = B01000000 ;
const int Masque128 = B10000000 ;
int RegistreA = 0xFF ;
char EPA0 = 1 ;
char EPA1 = 2 ;
char EPA2 = 4 ;
char EPA3 = 8 ;
char EPA4 = 16 ;
char EPA5 = 32 ;
char EPA6 = 64 ;
char EPA7 = 128 ;
char DePA0 = 1 ;
char DePA1 = 2 ;
char DePA2 = 4 ;
char DePA3 = 8 ;
char DePA4 = 16 ;
char DePA5 = 32 ;
char DePA6 = 64 ;
char DePA7 = 128 ;
int EPA0 = B00000001 ;
int EPA1 = B00000010 ;
int EPA2 = B00000100 ;
int EPA3 = B00001000 ;
int EPA4 = B00010000 ;
int EPA5 = B00100000 ;
int EPA6 = B01000000 ;
int EPA7 = B10000000 ;
int DePA0 = 1 ;
int DePA1 = 2 ;
int DePA2 = 4 ;
int DePA3 = 8 ;
int DePA4 = 16 ;
int DePA5 = 32 ;
int DePA6 = 64 ;
int DePA7 = 128 ;
void setup()
{
pinMode(22,INPUT);
pinMode(23,INPUT);
pinMode(24,INPUT);
pinMode(25,INPUT);
pinMode(26,INPUT);
pinMode(27,INPUT);
pinMode(28,INPUT);
pinMode(29,INPUT);
/* DDRA = B11111111 ; /* initialisation du port A en entré sur toutes les broches */
Serial.begin(31250); /* initialisation d'un port serie au debit MIDI */
noteOn( 0x80, 0x24 , 0x00 ) ;
noteOn( 0x80, 0x26 , 0x00 ) ;
noteOn( 0x80, 0x28 , 0x00 ) ;
noteOn( 0x80, 0x29 , 0x00 ) ;
noteOn( 0x80, 0x2B , 0x00 ) ;
noteOn( 0x80, 0x2D , 0x00 ) ;
noteOn( 0x80, 0x2F , 0x00 ) ;
noteOn( 0x80, 0x30 , 0x00 ) ;
}
@ -91,85 +111,50 @@ void noteOn(int cmd, int pitch, int velocity) /* plays a MIDI note. Doesn't chec
void setup()
{
pinMode(22,INPUT);
pinMode(23,INPUT);
pinMode(24,INPUT);
pinMode(25,INPUT);
pinMode(26,INPUT);
pinMode(27,INPUT);
pinMode(28,INPUT);
pinMode(29,INPUT);
pinMode(22,INPUT);
pinMode(23,INPUT);
Serial.begin(31250); /* initialisation d'un port serie au debit MIDI */
noteOn(0x80, 0x24 , 0x00 ) ; /* note off sur canal1 ; C2 ; vel 0 */
noteOn(0x80, 0x26 , 0x00 ) ; /* note off sur canal1 ; D2 ; vel 0 */
noteOn(0x80, 0x28 , 0x00 ) ; /* note off sur canal1 ; E2 ; vel 0 */
noteOn(0x80, 0x29 , 0x00 ) ;
noteOn(0x80, 0x2B , 0x00 ) ;
noteOn(0x80, 0x2D , 0x00 ) ;
noteOn(0x80, 0x2F , 0x00 ) ;
noteOn(0x80, 0x30 , 0x00 ) ;
}
void loop() void loop()
{ {
PortA = PINA ; /* lecture du port A */ RegistreA = PINA ; /* lecture du port A */
EPA0 = PortA & Masque1 ;
EPA1 = PortA & Masque2 ;
EPA2 = PortA & Masque4 ;
EPA3 = PortA & Masque8 ;
EPA4 = PortA & Masque16 ;
EPA5 = PortA & Masque32 ;
EPA6 = PortA & Masque64 ;
EPA7 = PortA & Masque128 ;
if ( ( EPA0 == 0 ) && ( DePA0 == 1 ) ) noteOn(0x90, 0x24 , 0x70 ) ; EPA0 = RegistreA & Masque1 ;
if ( ( EPA0 == 1 ) && ( DePA0 == 0 ) ) noteOn(0x80, 0x24 , 00 ) ; EPA1 = RegistreA & Masque2 ;
EPA2 = RegistreA & Masque4 ;
EPA3 = RegistreA & Masque8 ;
EPA4 = RegistreA & Masque16 ;
EPA5 = RegistreA & Masque32 ;
EPA6 = RegistreA & Masque64 ;
EPA7 = RegistreA & Masque128 ;
if ( ( EPA1 == 0 ) && ( DePA1 == 1 ) ) noteOn(0x90, 0x26 , 0x70 ) ; if ( ( EPA0 == 0 ) && ( DePA0 == 1 ) ) { noteOn(0x90, 0x24 , 0x70 ) ; }
if ( ( EPA1 == 1 ) && ( DePA1 == 0 ) ) noteOn(0x80, 0x26 , 00 ) ; if ( ( EPA0 == 1 ) && ( DePA0 == 0 ) ) { noteOn(0x80, 0x24 , 0x00 ) ;}
if ( ( EPA2 == 0 ) && ( DePA2 == 1 ) ) noteOn(0x90, 0x28 , 0x70 ) ;
if ( ( EPA2 == 1 ) && ( DePA2 == 0 ) ) noteOn(0x80, 0x28 , 00 ) ;
if ( ( EPA3 == 0 ) && ( DePA3 == 1 ) ) noteOn(0x90, 0x29 , 0x70 ) ;
if ( ( EPA3 == 1 ) && ( DePA3 == 0 ) ) noteOn(0x80, 0x29 , 00 ) ;
if ( ( EPA4 == 0 ) && ( DePA4 == 1 ) ) noteOn(0x90, 0x2B , 0x70 ) ;
if ( ( EPA4 == 1 ) && ( DePA4 == 0 ) ) noteOn(0x80, 0x2B , 00 ) ;
if ( ( EPA5 == 0 ) && ( DePA5 == 1 ) ) noteOn(0x90, 0x2D , 0x70 ) ; if ( ( EPA1 == 0 ) && ( DePA1 == Masque2 ) ) noteOn(0x90, 0x26 , 0x70 ) ;
if ( ( EPA5 == 1 ) && ( DePA5 == 0 ) ) noteOn(0x80, 0x2D , 00 ) ; if ( ( EPA1 == Masque2 ) && ( DePA1 == 0 ) ) noteOn(0x80, 0x26 , 0x00 ) ;
if ( ( EPA6 == 0 ) && ( DePA6 == 1 ) ) noteOn(0x90, 0x2F , 0x70 ) ;
if ( ( EPA6 == 1 ) && ( DePA6 == 0 ) ) noteOn(0x80, 0x2F , 00 ) ;
if ( ( EPA7 == 0 ) && ( DePA7 == 1 ) ) noteOn(0x90, 0x30 , 0x70 ) ;
if ( ( EPA7 == 1 ) && ( DePA7 == 0 ) ) noteOn(0x80, 0x30 , 00 ) ;
if ( ( EPA2 == 0 ) && ( DePA2 == Masque4 ) ) { noteOn(0x90, 0x28 , 0x70 ) ;}
if ( ( EPA2 == Masque4 ) && ( DePA2 == 0 ) ) { noteOn(0x80, 0x28 , 0x00 ) ; }
if ( ( EPA3 == 0 ) && ( DePA3 == Masque8 ) ) { noteOn(0x90, 0x29 , 0x70 ) ;}
if ( ( EPA3 == Masque8 ) && ( DePA3 == 0 ) ) {noteOn(0x80, 0x29 , 0x00 ) ;}
if ( ( EPA4 == 0 ) && ( DePA4 == Masque16 ) ) { noteOn(0x90, 0x2B , 0x70 ) ;}
if ( ( EPA4 == Masque16 ) && ( DePA4 == 0 ) ) { noteOn(0x80, 0x2B , 0x00 ) ;}
if ( ( EPA5 == 0 ) && ( DePA5 == Masque32 ) ) { noteOn(0x90, 0x2D , 0x70 ) ;}
if ( ( EPA5 == Masque32 ) && ( DePA5 == 0 ) ) { noteOn(0x80, 0x2D , 0x00 ) ;}
if ( ( EPA6 == 0 ) && ( DePA6 == Masque64 ) ) { noteOn(0x90, 0x2F , 0x70 ) ;}
if ( ( EPA6 == Masque64 ) && ( DePA6 == 0 ) ) { noteOn(0x80, 0x2F , 0x00 ) ;}
if ( ( EPA7 == 0 ) && ( DePA7 == Masque128 ) ) { noteOn(0x90, 0x30 , 0x70 ) ;}
if ( ( EPA7 == Masque128 ) && ( DePA7 == 0 ) ) { noteOn(0x80, 0x30 , 0x00 ) ;}
@ -187,237 +172,10 @@ void loop()
/* FIN */ /* FIN */
/* EtatEntree24 = digitalRead(24); }
EtatEntree25 = digitalRead(25);
EtatEntree26 = digitalRead(26);
EtatEntree27 = digitalRead(27);
EtatEntree28 = digitalRead(28);
EtatEntree29 = digitalRead(29);
EtatEntree30 = digitalRead(30);
EtatEntree31 = digitalRead(31);
EtatEntree32 = digitalRead(32);
EtatEntree33 = digitalRead(33);
EtatEntree34 = digitalRead(34);
EtatEntree35 = digitalRead(35); */
// if ( (EtatEntree24 != VarSuivi24) && (EtatEntree24 == HIGH) )
// {
// noteOn(0x80, 0x24 , 0x00) ; /* note off sur canal1 ; C2 ; vel 0 */
// /* Serial.println("touche lachee"); */
// VarSuivi24 = HIGH;
// }
//
// if ( (EtatEntree24 != VarSuivi24) && (EtatEntree24 == LOW) )
// {
// noteOn(0x90, 0x24 , 0x70) ; /* note on sur canal1 ; C2 ; vel */
// /* Serial.println("touche appuyee"); */
// VarSuivi24 = LOW;
// }
// if ( (EtatEntree25 != VarSuivi25) && (EtatEntree25 == HIGH) )
// {
// // noteOn(0x80, 0x25 , 0x00) ;
// VarSuivi25 = HIGH;
// }
// if ( (EtatEntree25 != VarSuivi25) && (EtatEntree25 == LOW) )
// {
// noteOn(0x90, 0x25 , 0x70) ; /* note on sur canal1 ; C2 ; vel */
// /* Serial.println("touche appuyee"); */
// VarSuivi25 = LOW;
// }
// if ( (EtatEntree26 != VarSuivi26) && (EtatEntree26 == HIGH) )
// {
// noteOn(0x80, 0x26 , 0x00) ; /* note off sur canal1 ; D2 ; vel 0 */
// /* Serial.println("touche lachee"); */
// VarSuivi26 = HIGH;
// }
// if ( (EtatEntree26 != VarSuivi26) && (EtatEntree26 == LOW) )
// {
// noteOn(0x90, 0x26 , 0x70) ; /* note on sur canal1 ; D2 ; vel */
// /* Serial.println("touche appuyee"); */
// VarSuivi26 = LOW;
// }
//
// if ( (EtatEntree27 != VarSuivi27) && (EtatEntree27 == HIGH) )
// {
// noteOn(0x80, 0x27 , 0x00) ; /* note off sur canal1 ; C2 ; vel 0 */
// /* Serial.println("touche lachee"); */
// VarSuivi27 = HIGH;
// }
//
// if ( (EtatEntree27 != VarSuivi27) && (EtatEntree27 == LOW) )
// {
// noteOn(0x90, 0x27 , 0x70) ; /* note on sur canal1 ; C2 ; vel */
// /* Serial.println("touche appuyee"); */
// VarSuivi27 = LOW;
// }
//
// if ( (EtatEntree28 != VarSuivi28) && (EtatEntree28 == HIGH) )
// {
// noteOn(0x80, 0x28 , 0x00) ; /* note off sur canal1 ; C2 ; vel 0 */
// /* Serial.println("touche lachee"); */
// VarSuivi28 = HIGH;
// }
//
// if ( (EtatEntree28 != VarSuivi28) && (EtatEntree28 == LOW) )
// {
// noteOn(0x90, 0x28 , 0x70) ; /* note on sur canal1 ; C2 ; vel */
// /* Serial.println("touche appuyee"); */
// VarSuivi28 = LOW;
// }
//
// if ( (EtatEntree29 != VarSuivi29) && (EtatEntree29 == HIGH) )
// {
// noteOn(0x80, 0x29 , 0x00) ; /* note off sur canal1 ; ; vel 0 */
// /* Serial.println("touche lachee"); */
// VarSuivi29 = HIGH;
// }
// if ( (EtatEntree29 != VarSuivi29) && (EtatEntree29 == LOW) )
// {
// noteOn(0x90, 0x29 , 0x70) ; /* note on sur canal1 ; C2 ; vel */
// /* Serial.println("touche appuyee"); */
// VarSuivi29 = LOW;
// }
// if ( (EtatEntree30 != VarSuivi30) && (EtatEntree30 == HIGH) )
// {
// noteOn(0x80, 0x2A , 0x00) ;
//
// VarSuivi30 = HIGH;
// }
// if ( (EtatEntree30 != VarSuivi30) && (EtatEntree30 == LOW) )
// {
// noteOn(0x90, 0x2A , 0x70) ;
// VarSuivi30 = LOW;
// }
// if ( (EtatEntree31 != VarSuivi31) && (EtatEntree31 == HIGH) )
// {
// noteOn(0x80, 0x2B , 0x00) ;
// VarSuivi31 = HIGH;
// }
// if ( (EtatEntree31 != VarSuivi31) && (EtatEntree31 == LOW) )
// {
// noteOn(0x90, 0x2B , 0x70) ;
//
// VarSuivi31 = LOW;
// }
//
// if ( (EtatEntree32 != VarSuivi32) && (EtatEntree32 == HIGH) )
// {
// noteOn(0x80, 0x2C , 0x00) ;
// VarSuivi32 = HIGH;
// }
// if ( (EtatEntree32 != VarSuivi32) && (EtatEntree32 == LOW) )
// {
// noteOn(0x90, 0x2C , 0x70) ;
// VarSuivi32 = LOW;
// }
// if ( (EtatEntree33 != VarSuivi33) && (EtatEntree33 == HIGH) )
// {
// noteOn(0x80, 0x2D , 0x00) ;
// VarSuivi33 = HIGH;
// }
// if ( (EtatEntree33 != VarSuivi33) && (EtatEntree33 == LOW) )
// {
// noteOn(0x90, 0x2D , 0x70) ;
// VarSuivi33 = LOW;
// }
// if ( (EtatEntree34 != VarSuivi34) && (EtatEntree34 == HIGH) )
// {
// noteOn(0x80, 0x2E , 0x00) ;
//
// VarSuivi34 = HIGH;
// }
// if ( (EtatEntree34 != VarSuivi34) && (EtatEntree34 == LOW) )
// {
// noteOn(0x90, 0x2E , 0x70) ;
// VarSuivi34 = LOW;
// }
// if ( (EtatEntree35 != VarSuivi35) && (EtatEntree35 == HIGH) )
// {
// noteOn(0x80, 0x2F , 0x00) ;
// VarSuivi35 = HIGH;
// }
//
// if ( (EtatEntree35 != VarSuivi35) && (EtatEntree35 == LOW) )
// {
// noteOn(0x90, 0x2F , 0x70) ;
//
// VarSuivi35 = LOW;
// }
/* // play notes from F#-0 (0x1E) to F#-5 (0x5A):
for (int note = 0x1E; note < 0x5A; note ++) {
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, note, 0x45);
delay(100);
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, note, 0x00);
delay(100); */
}