Hello i try to upload this scetch to my Arduino nano but it doesn't work, have anyone a idea? i try to restart trhe software and my pc, but it still not working.
The error code is:
avrdude: ser_open(): can't set com-state for "\.\COM22"
And this is the Code:
#include <Wire.h>
int faderA0_1 = analogRead(A0); //soloFader 1
int faderA1_2 = analogRead(A1); //soloFader 2
int faderA2_3 = analogRead(A2); //soloFader 3
int faderA3_4 = analogRead(A3); //soloFader 4
int faderA6_5 = analogRead(A6); //soloFader 5
int faderA7_6 = analogRead(A7); //soloFader 6
/*
int faderA0_1_Alt = 0;
int faderA1_2_Alt = 0;
int faderA2_3_Alt = 0;
int faderA3_4_Alt = 0;
int faderA6_5_Alt = 0;
int faderA7_6_Alt = 0;
*/
int recieve = 0;
bool test = false;
bool sendData = false;
bool buttonStat = false;
int Button1 = 2; //midiKnopf 1
int Button2 = 3; //midiKnopf 2
int Button3 = 4; //midiKnopf 3
int Button4 = 5; //midiKnopf 4
int Button5 = 6; //midiKnopf 5
int Button6 = 7; //midiKnopf 6
int Button7 = 8; //midiKnopf 7
int Button8 = 9; //midiKnopf 8
int Button9 = 10; //midiKnopf 9
int Button10 = 11; //midiKnopf 10
/*
int Button1_Alt = 0;
int Button2_Alt = 0;
int Button3_Alt = 0;
int Button4_Alt = 0;
int Button5_Alt = 0;
int Button6_Alt = 0;
int Button7_Alt = 0;
int Button8_Alt = 0;
int Button9_Alt = 0;
int Button10_Alt = 0;
*/
int ButtonI1 = 0;
int ButtonI2 = 0;
int ButtonI3 = 0;
int ButtonI4 = 0;
int ButtonI5 = 0;
int ButtonI6 = 0;
int ButtonI7 = 0;
int ButtonI8 = 0;
int ButtonI9 = 0;
int ButtonI10 = 0;
int Button1_neu = 0;
int Button2_neu = 0;
int Button3_neu = 0;
int Button4_neu = 0;
int Button5_neu = 0;
int Button6_neu = 0;
int Button7_neu = 0;
int Button8_neu = 0;
int Button9_neu = 0;
int Button10_neu = 0;
#define NODE_ADDRESS 2
#define PAYLOAD_SIZE 17
byte nodePayload[PAYLOAD_SIZE];
void setup() {
Serial.begin(9600);
Wire.begin(NODE_ADDRESS);
pinMode(Button1, INPUT_PULLUP);
pinMode(Button2, INPUT_PULLUP);
pinMode(Button3, INPUT_PULLUP);
pinMode(Button4, INPUT_PULLUP);
pinMode(Button5, INPUT_PULLUP);
pinMode(Button6, INPUT_PULLUP);
pinMode(Button7, INPUT_PULLUP);
pinMode(Button8, INPUT_PULLUP);
pinMode(Button9, INPUT_PULLUP);
pinMode(Button10, INPUT_PULLUP);
Wire.onReceive(receiveEvent); // erstelle ein Empfangen-Ereignis
Wire.onRequest(requestEvent); // erstelle ein Anfrage-Ereignis
Serial.println("lol");
}
void loop() {
faderA0_1 = analogRead(A0);
faderA1_2 = analogRead(A1);
faderA2_3 = analogRead(A2);
faderA3_4 = analogRead(A3);
faderA6_5 = analogRead(A6);
faderA7_6 = analogRead(A7);
Button1_neu = digitalRead(Button1);
Button2_neu = digitalRead(Button2);
Button3_neu = digitalRead(Button3);
Button4_neu = digitalRead(Button4);
Button5_neu = digitalRead(Button5);
Button6_neu = digitalRead(Button6);
Button7_neu = digitalRead(Button7);
Button8_neu = digitalRead(Button8);
Button9_neu = digitalRead(Button9);
Button10_neu = digitalRead(Button10);
if(Button1_neu ==LOW){
ButtonI1 = 1;
}else{
ButtonI1 = 0;
}
if(Button2_neu ==LOW){
ButtonI2 = 1;
}else{
ButtonI2 = 0;
}if(Button3_neu ==LOW){
ButtonI3 = 1;
}else{
ButtonI3 = 0;
}
if(Button4_neu ==LOW){
ButtonI4 = 1;
}else{
ButtonI4 = 0;
}
if(Button5_neu ==LOW){
ButtonI5 = 1;
}else{
ButtonI5 = 0;
}
if(Button6_neu ==LOW){
ButtonI6 = 1;
}else{
ButtonI6 = 0;
}
if(Button7_neu ==LOW){
ButtonI7 = 1;
}else{
ButtonI7 = 0;
}
if(Button8_neu ==LOW){
ButtonI8 = 1;
}else{
ButtonI8 = 0;
}
if(Button9_neu ==LOW){
ButtonI9 = 1;
}else{
ButtonI9 = 0;
}
if(Button10_neu ==LOW){
ButtonI10 = 1;
}else{
ButtonI10 = 0;
}
/*if(Button1_Alt != Button1_neu || Button2_Alt != Button2_neu || Button3_Alt != Button3_neu || Button4_Alt != Button4_neu || Button5_Alt != Button5_neu || Button6_Alt != Button6_neu || Button7_Alt != Button7_neu || Button8_Alt != Button8_neu || Button9_Alt != Button9_neu || Button10_Alt != Button10_neu){
buttonStat = true;
}else{
//Serial.println("nicht gedrückt");
}*/
}
void receiveEvent(int bytes) {
recieve = Wire.read(); // lies die gesendeten Daten aus
if(recieve==255){
test = true;
}
if(recieve==254){
sendData = true;
}
Serial.println(String(recieve) + ": recieve" + " test: " + test + " sendData: " + sendData);
}
void requestEvent()
{
Serial.println("buttonStat: " + String(buttonStat) + " sendData: " +sendData);
//Serial.println(String(faderA0_1_Alt) + " " + faderA0_1 + " " + faderA1_2_Alt + " " + faderA1_2 + " " + faderA2_3_Alt + " " + faderA2_3 + " " + faderA3_4_Alt + " " + faderA3_4 + " " + faderA6_5_Alt + " " + faderA6_5 + " " + faderA7_6_Alt + " " + faderA7_6);
//if(buttonStat == true || sendData == true || (faderA0_1_Alt != faderA0_1) || (faderA1_2_Alt != faderA1_2) || (faderA2_3_Alt != faderA2_3) || (faderA3_4_Alt != faderA3_4) || (faderA6_5_Alt != faderA6_5) || (faderA7_6_Alt != faderA7_6)){
nodePayload[0] = NODE_ADDRESS;
nodePayload[1] = faderA0_1 / 4;
nodePayload[2] = faderA1_2 / 4;
nodePayload[3] = faderA2_3 / 4;
nodePayload[4] = faderA3_4 / 4;
nodePayload[5] = faderA6_5 / 4;
nodePayload[6] = faderA7_6 / 4;
nodePayload[7] = ButtonI1;
nodePayload[8] = ButtonI2;
nodePayload[9] = ButtonI3;
nodePayload[10] = ButtonI4;
nodePayload[11] = ButtonI5;
nodePayload[12] = ButtonI6;
nodePayload[13] = ButtonI7;
nodePayload[14] = ButtonI8;
nodePayload[15] = ButtonI9;
nodePayload[16] = ButtonI10;
/*
faderA0_1_Alt = faderA0_1;
faderA1_2_Alt = faderA1_2;
faderA2_3_Alt = faderA2_3;
faderA3_4_Alt = faderA3_4;
faderA6_5_Alt = faderA6_5;
faderA7_6_Alt = faderA7_6;
Button1_Alt = Button1_neu;
Button2_Alt = Button2_neu;
Button3_Alt = Button3_neu;
Button4_Alt = Button4_neu;
Button5_Alt = Button5_neu;
Button6_Alt = Button6_neu;
Button7_Alt = Button7_neu;
Button8_Alt = Button8_neu;
Button9_Alt = Button9_neu;
Button10_Alt = Button10_neu;
sendData = false;
buttonStat = false;*/
Serial.println("data send" + String(nodePayload[0]));
Wire.write(nodePayload, PAYLOAD_SIZE);
/*}else if(test==true){
nodePayload[0] = NODE_ADDRESS;
nodePayload[1] = 255;
nodePayload[2] = 255;
nodePayload[3] = 255;
nodePayload[4] = 255;
nodePayload[5] = 255;
nodePayload[6] = 255;
Wire.write(nodePayload, PAYLOAD_SIZE);
test = false;
Serial.println("test passed");
}else{
//Wire.write(nodePayload, PAYLOAD_SIZE);
Serial.println("nicht gesendet");
}*/
//Wire.write(nodePayload, PAYLOAD_SIZE);
}