Ciao rieccomi dopo varie prove con le soluzioni da voi proposte ( che non ho compreso al 100% :~ ) sto provando con il codice di Uwe, visto che devo ricevere delle stringhe,in poche parole in questo mio primo progetto controllo 5 ds1802 che sono dei potenziometri audio a registri,a ogni ds a ho "associato" 16 case,
ora quando invio da 1 a 16 il controllo del primo è tutto ok ma quando arrivo a 17 mi controlla il secondo ma mi cambia anche il volume nel primo
//----------------------------------> CONTROLLO VOLUME 5 STANZE CON DS1802
int rstPin = 8; // pin rst sul chip pin 5
int clockPin = 12; // pin clock sul chip pin 3
int sala1 = 3; // pin dati Sala 1
int sala2 = 4; // pin dati Sala 2
int sala3 = 5; // pin dati Sala 3
int sala4 = 6; // pin dati Sala 4
int sala5 = 7; // pin dati Sala 5
#define VOL1 0x40 // MUTE
#define VOL2 0x2A
#define VOL3 0x27
#define VOL4 0x24
#define VOL5 0x21
#define VOL6 0x1E
#define VOL7 0x1B
#define VOL8 0x18
#define VOL9 0x15
#define VOL10 0x12
#define VOL11 0x0F
#define VOL12 0x0C
#define VOL13 0x09
#define VOL14 0x06
#define VOL15 0x03
#define VOL16 0x00 // VOLUME MASSIMO
unsigned int incomingByte;
char Data[4];
int i;
unsigned long Tempo;
//----------------------------------> CONTROLLO ACCENSIONE TELERUTTORE
int ledPin = 13; // PIN USCITA LED
int inPin = 9; // CONTATTO TELERUTTORE
int val = 0;
//----------------------------------> DEFINISCO GLI I/O
void setup() {
pinMode(rstPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(sala1, OUTPUT);
pinMode(sala2, OUTPUT);
pinMode(sala3, OUTPUT);
pinMode(sala4, OUTPUT);
pinMode(sala5, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(inPin, INPUT);
Serial.begin(9600);
Serial.println("attendo comando");
}
//----------------------------------> FUNZIONI DATI SALE
void out_sala1(int volume){
digitalWrite(rstPin, HIGH);
shiftOut(sala1,clockPin,LSBFIRST,volume); // POT-0
shiftOut(sala1,clockPin,LSBFIRST,volume); // POT-1
digitalWrite(rstPin, LOW);
}
void out_sala2(int volume2){
digitalWrite(rstPin, HIGH);
shiftOut(sala2,clockPin,LSBFIRST,volume2);
shiftOut(sala2,clockPin,LSBFIRST,volume2);
digitalWrite(rstPin, LOW);
}
void out_sala3(int volume3){
digitalWrite(rstPin, HIGH);
shiftOut(sala3,clockPin,LSBFIRST,volume3);
shiftOut(sala3,clockPin,LSBFIRST,volume3);
digitalWrite(rstPin, LOW);
}
void out_sala4(int volume4){
digitalWrite(rstPin, HIGH);
shiftOut(sala4,clockPin,LSBFIRST,volume4);
shiftOut(sala4,clockPin,LSBFIRST,volume4);
digitalWrite(rstPin, LOW);
}
void out_sala5(int volume5){
digitalWrite(rstPin, HIGH);
shiftOut(sala5,clockPin,LSBFIRST,volume5);
shiftOut(sala5,clockPin,LSBFIRST,volume5);
digitalWrite(rstPin, LOW);
}
//----------------------------------> LOOP
void loop(){
do {
if (Serial.available()) {
Data = Serial.read();
- i++;*
- } *
- if(i<1)Tempo = millis();*
- } while (i<4&&(millis()-Tempo) < 500);*
_ Data = 0; _
_ incomingByte = atof(Data); _
_ i=0;_
* switch (incomingByte){*
* case 1 :*
* out_sala1(VOL1);
_ break;*_
* case 2 :*
* out_sala1(VOL2);
_ break; *_
* case 3 :*
* out_sala1(VOL3);
_ break;*_
* case 4 :*
* out_sala1(VOL4);
_ break;*_
* case 5 :*
* out_sala1(VOL5);
_ break;*_
* case 6 :*
* out_sala1(VOL6);
_ break;*_
* case 7 :*
* out_sala1(VOL7);
_ break;*_
* case 8 :*
* out_sala1(VOL8);
_ break;*_
* case 9 :*
* out_sala1(VOL9);
_ break;*_
* case 10 :*
* out_sala1(VOL10);
_ break;*_
* case 11 :*
* out_sala1(VOL11);
_ break;*_
* case 12 :*
* out_sala1(VOL12);
_ break;*_
* case 13 :*
* out_sala1(VOL13);
_ break;*_
* case 14 :*
* out_sala1(VOL14);
_ break;*_
* case 15 :*
* out_sala1(VOL15);
_ break;*_
* case 16 :*
* out_sala1(VOL16);
_ Serial.print("SEDICI");_
_ break;*_
*//----------------------------------> SALA 2 *
* case 17 :*
* out_sala2(VOL1);
_ Serial.print("DICIASSETTE");_
_ break;*_
* case 18 :*
* out_sala2(VOL2);
_ break; *_
* case 19 :*
* out_sala2(VOL3);
_ break;*_
* case 20 :*
* out_sala2(VOL4);
_ break;*_
* case 21 :*
* out_sala2(VOL5);
_ break;*_
* case 22 :*
* out_sala2(VOL6);
_ break;*_
* case 23 :*
* out_sala2(VOL7);
_ break;*_
* case 24 :*
* out_sala2(VOL8);
_ break;*_
* case 25 :*
* out_sala2(VOL9);
_ break;*_
* case 26 :*
* out_sala2(VOL10);
_ break;*_
* case 27 :*
* out_sala2(VOL11);
_ break;*_
* case 28 :*
* out_sala2(VOL12);
_ break;*_
* case 29 :*
* out_sala2(VOL13);
_ break;*_
* case 30 :*
* out_sala2(VOL14);
_ break;*_
* case 31 :*
* out_sala2(VOL15);
_ break;*_
* case 32 :*
* out_sala2(VOL16);
_ break;_
_//----------------------------------> SALA 3 *_
* case 33 :*
* out_sala3(VOL1);
_ break;*_
* case 34 :*
* out_sala3(VOL2);
_ break; *_
* case 35 :*
* out_sala3(VOL3);
_ break;*_
* case 36 :*
* out_sala3(VOL4);
_ break;*_
* case 37 :*
* out_sala3(VOL5);
_ break;*_
* case 38 :*
* out_sala3(VOL6);
_ break;*_
* case 39 :*
* out_sala3(VOL7);
_ break;*_
* case 40 :*
* out_sala3(VOL8);
_ break;*_
* case 41 :*
* out_sala3(VOL9);
_ break;*_
* case 42 :*
* out_sala3(VOL10);
_ break;*_
* case 43 :*
* out_sala3(VOL11);
_ break;*_
* case 44 :*
* out_sala3(VOL12);
_ break;*_
* case 45 :*
* out_sala3(VOL13);
_ break;*_
* case 46 :*
* out_sala3(VOL14);
_ break;*_
* case 47 :*
* out_sala3(VOL15);
_ break;*_
* case 48 :*
* out_sala3(VOL16);
_ break;*_
*//----------------------------------> SALA 4 *
* case 49 :*
* out_sala4(VOL1);
_ break;*_
* case 50 :*
* out_sala4(VOL2);
_ break;*_
* case 51 :*
* out_sala4(VOL3);
_ break;*_
* case 52 :*
* out_sala4(VOL4);
_ break;*_
* case 53 :*
* out_sala4(VOL5);
_ break;*_
* case 54 :*
* out_sala4(VOL6);
_ break;*_
* case 55 :*
* out_sala4(VOL7);
_ break;*_
* case 56 :*
* out_sala4(VOL8);
_ break;*_
* case 57 :*
* out_sala4(VOL9);
_ break;*_
* case 58 :*
* out_sala4(VOL10);
_ break;*_
* case 59 :*
* out_sala4(VOL11);
_ break;*_
* case 60 :*
* out_sala4(VOL12);
_ break;*_
* case 61 :*
* out_sala4(VOL13);
_ break;*_
* case 62 :*
* out_sala4(VOL14);
_ break;*_
* case 63 :*
* out_sala4(VOL15);
_ break;*_
* case 64 :*
* out_sala4(VOL16);
_ break; _
_//----------------------------------> SALA 5 *_
* case 65 :*
* out_sala5(VOL1);
_ break;*_
* case 66 :*
* out_sala5(VOL2);
_ break; *_
* case 67 :*
* out_sala5(VOL3);
_ break;*_
* case 68 :*
* out_sala5(VOL4);
_ break;*_
* case 69 :*
* out_sala5(VOL5);
_ break;*_
* case 70 :*
* out_sala5(VOL6);
_ break;*_
* case 71 :*
* out_sala5(VOL7);
_ break;*_
* case 72 :*
* out_sala5(VOL8);
_ break;*_
* case 73 :*
* out_sala5(VOL9);
_ break;*_
* case 74 :*
* out_sala5(VOL10);
_ break;*_
* case 75 :*
* out_sala5(VOL11);
_ break;*_
* case 76 :*
* out_sala5(VOL12);
_ break;*_
* case 77 :*
* out_sala5(VOL13);
_ break;*_
* case 78 :*
* out_sala5(VOL14);
_ break;*_
* case 79 :*
* out_sala5(VOL15);
_ break;*_
* case 80 :*
* out_sala5(VOL16);
_ break;_
_}}_
_[/quote]*_