Hello,
When I open the Serial Monitor it is just printing these reversed question marks and I dont know why. Can anybody help me please?
int laser = A3;
int led1 = 4;
int led2 = 1;
int fotocelda1 = A0;
int fotocelda2 = A1;
int fotocelda3 = A2;
int motorRF = 6;
int motorRB = 9;
int motorLF = 5;
int motorLB = 3;
// Declaracion de constantes
int vidas = 3;
int tFoto1, tFoto2, tLaser1, tLaser2;
boolean impacto = true;
boolean disparo = true;
void setup() {
// Estado de los pines
pinMode(laser,OUTPUT);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(fotocelda1, INPUT);
pinMode(motorRF,OUTPUT);
pinMode(motorRB,OUTPUT);
pinMode(motorLF,OUTPUT);
pinMode(motorLB,OUTPUT);
//#include <SoftwareSerial.h>
//#define txPin 4
//#define rxPin 2
//SoftwareSerial BLE(rxPin, txPin);
//BLE.begin(9600);
Serial.begin(9600);
}
void loop()
{
//int valorFotocelda = analogRead(fotocelda1);
int valorFotocelda = 0;
if (vidas == 2) {
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
}
char instruccion = Serial.read();
char vida = '2';
Serial.println(instruccion);
if (instruccion == '1' && disparo == true)
{
analogWrite(laser, 255);
tLaser1 = millis();
disparo = false;
Serial.write(vida);
}
if (instruccion == 'B' || instruccion == 'D' || instruccion == 'F' || instruccion == 'H') {
digitalWrite(motorRF, 0);
digitalWrite(motorRB, 0);
digitalWrite(motorLF, 0);
digitalWrite(motorLB, 0);
}
if (instruccion == 'A') {
digitalWrite(motorRF, 255);
digitalWrite(motorRB, 0);
digitalWrite(motorLF, 255);
digitalWrite(motorLB, 0);
}
if (instruccion == 'C') {
digitalWrite(motorRF, 0);
digitalWrite(motorRB, 255);
digitalWrite(motorLF, 0);
digitalWrite(motorLB, 255);
}
if (instruccion == 'E') {
digitalWrite(motorRF, 255);
digitalWrite(motorRB, 0);
digitalWrite(motorLF, 0);
digitalWrite(motorLB, 255);
}
if (instruccion == 'G') {
digitalWrite(motorRF, 0);
digitalWrite(motorRB, 255);
digitalWrite(motorLF, 255);
digitalWrite(motorLB, 0);
}
tLaser2 = millis();
if ( tLaser2 - tLaser1 > 3000 )
{
analogWrite(laser, 0);
}
if ( tLaser2 - tLaser1 > 8000 )
{
disparo = true;
}
if ( impacto == true )
{
if ( valorFotocelda > 800 ) {
vidas = vidas - 1;
tFoto1 = millis();
}
}
tFoto2 = millis();
if ( vidas == 1) {
digitalWrite(led1, LOW);
impacto = false;
}
if (tFoto2 - tFoto1 > 3000) {
impacto = true;
}
if ( vidas == 0 ) {
digitalWrite(led2, LOW);
}
}
