I have a task where I need to control the airplanes thrust and altitude direction(Up-Down). For the thrust I thought of using a DC Motor and a Servo for the other. Control of servo will be from the buttons and the thrust value will be given from the serial port. (This is not a project of a real vehicle, only thing I need to do is the code, rest is imaginary.)

I have wrote the following code. I would like to ask is there any flaws and how can I further improve it? Thanks in advance.
With my regards...

1 Answer
1

while (! Serial); Is not needed if you have a board with USB-> Serial bridge Chip (arduino uno for example)

if(buttonStateDOWN=HIGH){
}

In every condition you used = instead of ==. Your "condition" actually assigns HIGH to buttonStateDOWN. If you want to compare integers, use ==.

And according to the question, I think you have misunderstood the speed buttons (or maybe I have). I think, they want you to code it so while the button is pressed or every time the button is pressed, the speed changes by +1 or -1.

Assuming the rest works fine, there could be a problem with your serial output, since you just spam messages.

Read about the millis();, it can help you so you only send something every x amount of seconds, without using delay();Here