LED
warning
The document is a continuation of the previous document, if you have landed directly on this page then, Please read from page Get started.
What is LED?
LED is an electronic device which emits light when current passes through it. It is used as a visual Indicator in Industries.
List of LED features implemented in Shunya stack
With Shunya stack you can make LED
- Turn On/Off.
Using Led Shunya stack
Requirements to use Led Shunya stack
- Shunya OS installed (supported Arm devices) i.e (Raspberry Pi)
- 1x LED
- 1x 220 ohm resistor
Steps to use Led Shunya stack
- Connect LED to your Arm device i.e (Raspberry Pi) .
- Turn On/Off LED.
note
Run the steps given below inside Shunya OS installed (supported Arm devices).
Step 1: Connect LED.
Step 2: Turn On/Off LED.
Let's take an example use case: Say we need to
- Read data from the temperature sensor connected to Shunya and,
- Turn on LED when the temperature is high.
Steps are :
Start with an ready to use template for sending messages via MQTT
git clone https://gitlab.iotiot.in/repo-public/examples.git
cd examples/simple-examples/operate-actuatorsOpen the
operate-actuators.c
in an text editor and modify as per your use case.For our example, we need to first get the temperature data, add the code in your
main()
functionfloat temperature = 76.98; /* For now lets assume that the temperature is 76.89 Celsius*/
Initialize LED, modify the code
int ledPin = 36; /*Define LED pin, Note this should be as per your connection */
pinMode(ledPin, OUTPUT); /* Initializes LED pin as Output */warning
LED should be initialized only once in the whole program. Calling
pinMode()
multiple times will cause error with the library.To turn on LED, modify the code
float temperature = 76.89; /* Assume that the temperature is 76.89 deg C*/
if (temperature == 70.00f){
digitalWrite(ledPin, ON); /* Turn on LED */
} else {
digitalWrite(ledPin, OFF); /* Turn off LED */
}Once you are done editing, save and compile the code , by running
mkdir build && cd build
cmake ../
makeRun the code
sudo ./operate-actuators