Blinking an LED CloudX
The Light Emitting Diode (LED) is one of the most popular electronic components; it is widely used as an indicator. The LED has two terminals which are the Anode (+) and the Cathode (-), the longer pin is always the anode while the shorter pin is always the cathode .
Our tutorial we will focus on blinking an LED. The cloudx microcontroller can sink (absorb) and source (give out) a small amount of current, so we can connect the LED directly to the digital pins. We will use a resistor of about 220R to limit the flow of current across the LED.
Before we start our first breadboard project, there’s an onboard green LED on the microcontroller that is connected to pin1, it was intentionally placed on the board so that users can test the microcontroller board by blinking the LED.
Now, to blink the onboard green LED, Connect your Softcard and the Controller to your computer. Open the cloudx IDE and create a new project, you check chapter two again to understand how to create a project and writing to pin1.
Design the circuit below on a breadboard; you can learn more on how to use a breadboard at Science Buddies.
- CloudX Controller
- CloudX SoftCard
- CloudX USB Cable
- Male – Male Wires
pin1Mode = OUTPUT;
pin1 = HIGH;
pin1 = LOW;
The #include must always be in every of our codes as allows the compiler to understand your programming language, if not included, then the compiler would generate errors.
The setup() is a place where the program first get to when powered up before doing any other thing in the project. Programmers are meant to do their settings in this place before entering the loop function.
The loop () is a place where your program stays forever, this can also be liken to as while(1) or for(;;) which means an endless loop. It keeps repeating every statement inside it forever.
pinxMode can be used to configure a digital pin either as output or input, where x represents digits from 1 to 16. In the example above, I used configured pin1 as output and that’s why I used pin1Mode = OUTPUT;while pin1 = HIGH means that we are loading a positive 5V into pin1, delay(x)is used to delay the program where x is in millisecond. Now having delay(1000) means we have delayed the ON time(5V) on pin1 for 1000ms(1second) before another step of instruction, the pin1 = LOW is used to load 0v into the pin1 (OFF the pin) and delay for another 1second. The program keeps repeating the loop forever which makes the LED to appear as if it is blinking.