Hello david_uwi and Pete, thanks for your replies.
Pete: as david_uwi mentioned the idea is to connect an Arduino board to a computer via USB cable. So the thread you show here is interesting, but unrelated. I would love to had a parallel port, but as you know computer manufacturers have shifted mostly to USB ports, so they are kind of universal.
david_uwi: we are not using a display by two reasons: 1) we want a bigger screen XD and 2) more functionality, as .txt files with the times and laps proccesed by QB64, so we can have a long register of the races and practices, names of the cars to compare between them... and a long possible etc. This is why the uC program should be minimalistic, avoiding a more complex lenguage with less OUTPUT and INPUT in exchange for simple interpreter that comunicates with a more complex program, that can be expanded to God knows how much and with better periphericals for input and output. About the optical sensor vs reed switches: agree that is a better idea, but we short on hardware, We have reed switches, no problem on that. When we get the hardware we will change to optical.
So yes, we gonna connect the Arduino board to the computer by USB cable, we gonna program the uC to gives us the reading of the reed switches and control 3 transistors (one for each traffic light: conventional g,y&r). The QB64 should direct wich of the light is on according to a byte sended to the uC board and register every moment of the reed switches from what it receives from the uC
I tried this program on the Arduino:
//pines del Arduino al que están conectados los transistor que disparan las luces del semáforo
const int semaforoRojo = 10;
const int semaforoAmrillo = 9;
const int semaforoVerde = 8;
//pines del Arduino a los que están conectados los reed switch
const int reedVerde = 2;
const int reedRojo = 3;
//VARIABLES DE PROGRAMA
const int tiempoDebounce = 2000;//modificar para alterar el tiempo de espera del debounce de los reed switch, no debe ser > 32767
int valReedVnuevo;//lectura del reed verde
int valReedRnuevo;//lectura del reed rojo
int valReedVviejo;//lectura anterior del reed verde (debounce)
int valReedRviejo;//lectura anterior del reed rojo (debounce)
int readFromSerial;//lectura de lo que viene de la PC
int writeToSerial;//escritura que vamos a realizar hacie el PC
void setup() {
Serial.begin(9600);
pinMode (semaforoRojo, OUTPUT);
pinMode (semaforoAmrillo, OUTPUT);
pinMode (semaforoVerde, OUTPUT);
pinMode (reedVerde, INPUT);
pinMode (reedRojo, INPUT);
}
void loop() {
valReedVnuevo = digitalRead (reedVerde);
valReedRnuevo = digitalRead (reedRojo);
// Serial, println (valReedVnuevo, valReedRnuevo);
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
readFromSerial = Serial.read();
// say what you got:
Serial.println(readFromSerial, DEC);
}
delay(10);
}
with this program of QB64:
INPUT "COM port number #", port$
'any COM port number available
'receive data in buffer when LOC > 0
PRINT "[" + bytestr
+ "]";
'transmit (send)
IF k
>= 32 THEN 'ignore control key codes bytestr
= k$:
PUT #1, , bytestr
The board is connected to port 3, so imdirect QB64 to 3 as well, but i get this error. The only parameter asked for the uC seems to be the baud rate (used 9600), whic is also one of the parameters in the OPEN COM instruction, but i don't really understand if the rest of the parameters in the OPEN COM are ok. I've read the wiki about the command, but i'm not sure what kind of parameters i should be using, or if this have nothing to do with the error i'm getting.
Again, thanks for the replies and cheers.