Posts

Showing posts from August, 2018

Controlling Servos

Controlling Servos Look at the page on the Mechatronics website for info on how to control a servo from the Arduino board. It is in the Year 10 pull down menu, called Servos. Once you have the servo hooked up and moving try altering the program to make it move in an interesting way.

Better millis() program

Image
Better millis() program This program introduces a variable called ledOn to record whether the LED is on or off. It is a Boolean datatype as this can only take 2 values true or false making the if statement easier. So before the program turns the LED on and resets the 'start' value BOTH the switch has to be closed AND (&&) the LED has to be off. So if you press the switch when the LED is already on the program won't do anything. Happy days. :-)

Programs without Delay

Image
Program and setup to control LED using millis not delay The breadboard was set up with 5V power and Ground from the Uno board. A 3K pull-down resistor was connected from the negative rail to a free row on the breadboard. Pin 7 was connected to the same row. A switch was connected from that row with the middle pin 2 rows down and the last pin 4 rows down The positive rail was connected to the row the middle pin was in. This program turns the internal LED on when the switch is closed and then off again 2 seconds later. The time, state of the switch and state of the LED can be viewed on the serial monitor. 0 is low and 1 is high. Yeah..it works. The pull down resistor ensures that pin 7 goes low when the switch is opened which was screwing up my previous attempts. The problem with this program is that if the switch is pressed whilst the LED is on the value of 'start' is reset to the current millis() value so the LED really goes off 2 seconds after the switch is l...