I am a beginner with microcontroller programming and I am sorry if my problem is very trivial. But I hope that someone can help me to move my work forward, because I got stuck…
I want to control a bipolar transistor with arduino, but setting it high and low via messages received on a serial port. That is easy and works great without issues.
The problem is, that in the arduino sketch, which I must use for controlling other device, there is already one variable reading bytes from a serial port. And when both of them (variable for the transistor and for the other device) are active, then only the second one (for the other device) reads data from serial…
Do you know why it is like this and how can I “choose” which variable will be reading the data?
For controlling the transistor I just send two different letters, let’s say c and d for low and high.
For controlling the device there are byte packages send in order to control voltage/current.
And this is not good if my device receives “dumb” messages like “c” or “d”, because there could be a problem with current or voltage which are set…
Here is my code for the transistor:
And here the other variable, which when active, disactivates the other one:
if (Serial.available() > 0)
unsigned long timeOut = 0;
commandByte = Serial.read();
Serial.println("Command byte: ");
for (byte i = 0; i < ((commandByte & 0b01100000) >> 5); i++)
I will be very thankful if someone could tell me, where the problem is.