This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:remotelab:ume:smartme:b3 [2019/09/27 16:43] – salvatdi | en:iot-open:remotelab:ume:smartme:b3 [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== B3: PWM mode (~) of digital pins, programming threshold values | + | ==== IB3: PWM mode (~) of digital pins, programming threshold values ==== |
| - | ===== Target group ===== | + | === Target group === |
| This hands-on lab guide is intended for the Beginners but other target groups may benefit from it, treating it as a tool for advanced projects. | This hands-on lab guide is intended for the Beginners but other target groups may benefit from it, treating it as a tool for advanced projects. | ||
| - | ===== Prerequisites | + | === Prerequisites === |
| - | ==== Liquid Crystal | + | == Liquid Crystal == |
| For this library, you may refer to the [[en: | For this library, you may refer to the [[en: | ||
| - | ==== RGB LED ==== | + | == RGB LED == |
| The SmartME Network Laboratory Arduino nodes 1-5 are equipped with an RGB LED. | The SmartME Network Laboratory Arduino nodes 1-5 are equipped with an RGB LED. | ||
| To connect other devices, however, only the green light component is available, exposed as a separate LED. | To connect other devices, however, only the green light component is available, exposed as a separate LED. | ||
| Line 20: | Line 20: | ||
| You can make the LED flashing by tuning the delay of HIGH and LOW states. | You can make the LED flashing by tuning the delay of HIGH and LOW states. | ||
| The digital pins either give you 5V (when turned HIGH) or 0V (when turned LOW) and the output is a square wave signal. | The digital pins either give you 5V (when turned HIGH) or 0V (when turned LOW) and the output is a square wave signal. | ||
| - | PWM stands for Pulse Width Modulation and it is a technique used in controlling the brightness of the LED. The PWM pins are labeled | + | PWM stands for Pulse Width Modulation and it is a technique used in controlling the brightness of the LED. The PWM pins are labelled |
| - | The function analogWrite() can be used to generate a PWM signal in those digital pins that are labeled | + | The function analogWrite() can be used to generate a PWM signal in those digital pins that are labelled |
| * analogWrite(0) means a signal of 0% duty cycle. | * analogWrite(0) means a signal of 0% duty cycle. | ||
| * analogWrite(127) means a signal of 50% duty cycle. | * analogWrite(127) means a signal of 50% duty cycle. | ||
| Line 27: | Line 27: | ||
| The function random() generates pseudo-random numbers. The syntax is random(max) or random(min, max), where min represents the lower bound of the random value, inclusive (optional); and max represents the upper bound of the random value, exclusive. The function returns a long random number between min and max-1. | The function random() generates pseudo-random numbers. The syntax is random(max) or random(min, max), where min represents the lower bound of the random value, inclusive (optional); and max represents the upper bound of the random value, exclusive. The function returns a long random number between min and max-1. | ||
| - | === The circuit | + | == The circuit: == |
| RGB GREEN pin = Arduino pin 3 (~) | RGB GREEN pin = Arduino pin 3 (~) | ||
| - | ===== Scenario | + | === Scenario === |
| Initialize the LCD screen with the label “rand value”, then calculates a random value. If randomValue is lower than lowThreshold, | Initialize the LCD screen with the label “rand value”, then calculates a random value. If randomValue is lower than lowThreshold, | ||
| - | ===== Result | + | === Result === |
| You should see the LED on or off for 1 second, a second if the value is greater or less than the predefined threshold values. Next, you should see the randomly calculated value between 0 and 255 on the LCD, at that point, the LED should assign a brightness associated with that value, and keep it for 3 seconds. | You should see the LED on or off for 1 second, a second if the value is greater or less than the predefined threshold values. Next, you should see the randomly calculated value between 0 and 255 on the LCD, at that point, the LED should assign a brightness associated with that value, and keep it for 3 seconds. | ||
| - | ===== Start ===== | + | === Start === |
| There are no special steps to be performed. | There are no special steps to be performed. | ||
| - | ===== Steps ===== | + | === Steps === |
| - | ==== Step 1 ==== | + | == Step 1 == |
| Include the LCD driver library: | Include the LCD driver library: | ||
| <code c> | <code c> | ||
| Line 48: | Line 48: | ||
| </ | </ | ||
| - | ==== Step 2 ==== | + | == Step 2 == |
| Instantiate the software controller component for the LCD display. Initialize the LED pin. Declare the threshold values. | Instantiate the software controller component for the LCD display. Initialize the LED pin. Declare the threshold values. | ||
| Line 62: | Line 62: | ||
| </ | </ | ||
| - | ==== Step 3 ==== | + | == Step 3 == |
| Initialize the display and declare the LED pin as OUTPUT - preferably in the setup() function: | Initialize the display and declare the LED pin as OUTPUT - preferably in the setup() function: | ||
| Line 74: | Line 74: | ||
| - | ==== Step 4 ==== | + | == Step 4 == |
| Implement loop() to do in the order: | Implement loop() to do in the order: | ||
| calculate a random value between 0 and 255; | calculate a random value between 0 and 255; | ||
| Line 100: | Line 100: | ||
| - | ===== Result validation | + | === Result validation === |
| The state of the LED will depend on the random number calculated and on the threshold values that have been set. | The state of the LED will depend on the random number calculated and on the threshold values that have been set. | ||
| The random value will be shown by the display monitor. | The random value will be shown by the display monitor. | ||
| It also will affect the LED brightness for 3 seconds. | It also will affect the LED brightness for 3 seconds. | ||
| - | ===== Platformio.ini | + | === Platformio.ini === |
| < | < | ||
| [env:uno] | [env:uno] | ||
| Line 120: | Line 120: | ||
| </ | </ | ||
| - | ===== B3.cpp ===== | + | === IB3.cpp === |