Try to narrow the error down: run another program on the board. If the problem persists, it's not the program that's causing the issue.
It's from my program now, but where can it come from?
I've been looking for 2 days but I can't find it...
avrdude: ser_open(): can't set com-state for ".\COM4"
this is a problem with the connection, not with the Sketch code.
Plug into another USB port, correctly set the port in the Arduino IDE, correctly load the Arduino driver...
This code is not finished, but you can study it...
BTabc.aia (14.4 KB)
#include <SoftwareSerial.h>
#define rxPin 11 // Pin 11 as RX, connected to TX of HC-05
#define txPin 10 // Pin 10 as TX, connected to RX of HC-05
SoftwareSerial mySerial(10,11);
int player1 = 0;
int turnNumber = 1;
int maxTurns = 100;
bool endGame = false;
// TARGET1
int ledTarget1 = 2;
int switchTarget1 = A0;
long previousMillisTarget1 = 0;
long intervalTarget1 = 1000;
bool isTargetHit1 = false;
// END TARGET1
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
pinMode(ledTarget1, OUTPUT);
//pinMode(rxPin, INPUT);
//pinMode(txPin, OUTPUT);
Serial.println(String(player1) + "|" + String(turnNumber) + "|" + String(endGame));
}
void loop() {
String customKey = "";
if (mySerial.available() > 0) {
customKey = mySerial.readString();
//customKey = mySerial.readStringUntil('\n');
Serial.println(customKey);
}
if (turnNumber == maxTurns) {
turnNumber = 1;
delay(1500);
Serial.println(String(player1) + "|" + String(turnNumber) + "|" + String(endGame));
}
if (customKey == "service failed") {
turnNumber++;
Serial.println(String(player1) + "|" + String(turnNumber) + "|" + String(endGame));
}
if (customKey == "start") {
endGame = false;
player1 = 0;
turnNumber = 1;
Serial.println(String(player1) + "|" + String(turnNumber) + "|" + String(endGame));
mySerial.println(String(player1) + "|" + String(turnNumber) + "|" + String(endGame));
}
checkTarget1();
}
void checkTarget1() {
int switchValue = analogRead(switchTarget1);
if (switchValue > 0 && !isTargetHit1) {
digitalWrite(ledTarget1, HIGH);
isTargetHit1 = true;
player1++;
turnNumber++;
Serial.println(String(player1) + "|" + String(turnNumber) + "|" + String(endGame));
mySerial.println(String(player1) + "|" + String(turnNumber) + "|" + String(endGame));
}
unsigned long currentMillis = millis();
if (currentMillis - previousMillisTarget1 > intervalTarget1) {
previousMillisTarget1 = currentMillis;
isTargetHit1 = false;
digitalWrite(ledTarget1, LOW);
}
}
Hi, when I put the code, same error as before, I don't know where it can come from, if you could still help me really sorry
avrdude: ser_open(): can't set com-state for ".\COM4"
this is a problem with the connection
Try with driver ch341
http://kio4.com/arduino/1inicio.htm