You are viewing an older revision! See the latest version
Analog inputs and outputs
All exercises in this topic will be carried out using an mbed application board. The board has 3 inputs prepared for use with an AnalogIn
class. Two potenciometers (Pot1 and Pot2) are connected to pins p19 and p20, respectively, and 3.5 mm audio jack is connected to pin p17.
Since mbed NXP LPC1768 has only one analog output on pin p18, mbed application board uses that output via another 3.5 mm audio jack.
You will examine the use of potenciometers as analog inputs in Exercise 1, analog outputs in Exercise 2 and analog communication between two mbeds in Exercise 3.
Exercise 1: Using potenciometers as analog inputs¶
Write a program that will read the inputs of potentiometers Pot1 and Pot2, calculate the average reading of two potentiometers, and based on the average reading value, turn on or off the four onboard mbed LEDs. Use the following table as rules for LEDs control:
Average reading x | LED1 | LED2 | LED3 | LED4 |
x <= 0.2 | 0 | 0 | 0 | 0 |
0.2 < x <= 0.4 | 1 | 0 | 0 | 0 |
0.4 < x <= 0.6 | 1 | 0 | 0 | 0 |
0.6 < x <= 0.8 | 1 | 0 | 0 | 0 |
0.8 < x <= 1 | 1 | 0 | 0 | 0 |
Write your own solution of the program, test it and then compare to the solution given below.
Import programMAB_Potenciometers
Using potenciometers as analog inputs.