Reading an Analog Signal
Read an analog Signal and display the output
Components Required
Introduction
Theory
Methodology
For this example, we use the potentiometer on the Magicbit board, which is connected to pin, D39. It generates a voltage between 0 and 3.3V according to the angle of the potentiometer.
We read the analog signal and store it in an int type variable(0v= 0 analog value, 3.3v = 4096 analog value), sensorValue, later, we use this value to light up the red LED(D27) if the analog value exceeds 2048.
Script
Explanation
This program starts by clicking the green flag. The forever block continuously runs the code held inside the block. ‘If and else’ block controls the script according to the value of the potentiometer. If the potentiometer reading is greater than 512 then, the “Set digital pin [pin] [state]” block sets the digital pin 27 to “HIGH” and else sets the digital pin 27 to “LOW”.
Note: Do the same example using the LDR on the board (D36)