
Display pot. value
Fork of IPI_Singapore_Workshop by
main.cpp@2:10f92fa42985, 2017-11-22 (annotated)
- Committer:
- alansim
- Date:
- Wed Nov 22 07:59:57 2017 +0000
- Revision:
- 2:10f92fa42985
- Parent:
- 1:2792d77cc2cc
Revision Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nprobably | 0:4ebd37a7a0ac | 1 | //---------------------------------------------------------------------------- |
nprobably | 0:4ebd37a7a0ac | 2 | // The confidential and proprietary information contained in this file may |
nprobably | 0:4ebd37a7a0ac | 3 | // only be used by a person authorised under and to the extent permitted |
nprobably | 0:4ebd37a7a0ac | 4 | // by a subsisting licensing agreement from ARM Limited or its affiliates. |
nprobably | 0:4ebd37a7a0ac | 5 | // |
nprobably | 0:4ebd37a7a0ac | 6 | // (C) COPYRIGHT 2016 ARM Limited or its affiliates. |
nprobably | 0:4ebd37a7a0ac | 7 | // ALL RIGHTS RESERVED |
nprobably | 0:4ebd37a7a0ac | 8 | // |
nprobably | 0:4ebd37a7a0ac | 9 | // This entire notice must be reproduced on all copies of this file |
nprobably | 0:4ebd37a7a0ac | 10 | // and copies of this file may only be made by a person if such person is |
nprobably | 0:4ebd37a7a0ac | 11 | // permitted to do so under the terms of a subsisting license agreement |
nprobably | 0:4ebd37a7a0ac | 12 | // from ARM Limited or its affiliates. |
nprobably | 0:4ebd37a7a0ac | 13 | //---------------------------------------------------------------------------- |
nprobably | 0:4ebd37a7a0ac | 14 | |
nprobably | 0:4ebd37a7a0ac | 15 | #include "mbed.h" |
nprobably | 0:4ebd37a7a0ac | 16 | |
nprobably | 0:4ebd37a7a0ac | 17 | // GLOBAL VARIABLES HERE |
alansim | 2:10f92fa42985 | 18 | AnalogIn pot1(A0); |
alansim | 2:10f92fa42985 | 19 | EventQueue queue; |
nprobably | 0:4ebd37a7a0ac | 20 | |
nprobably | 0:4ebd37a7a0ac | 21 | // FUNCTION DEFINITIONS HERE |
alansim | 2:10f92fa42985 | 22 | void read_potentiometer() { |
alansim | 2:10f92fa42985 | 23 | static float potentiometer_val = 0; |
alansim | 2:10f92fa42985 | 24 | if ((float)pot1 != potentiometer_val) { |
alansim | 2:10f92fa42985 | 25 | potentiometer_val = (float)pot1; |
alansim | 2:10f92fa42985 | 26 | printf("Analog Reading: %.2f\r\n", potentiometer_val); |
alansim | 2:10f92fa42985 | 27 | } |
alansim | 2:10f92fa42985 | 28 | } |
nprobably | 0:4ebd37a7a0ac | 29 | |
alansim | 2:10f92fa42985 | 30 | |
nprobably | 0:4ebd37a7a0ac | 31 | int main() |
nprobably | 0:4ebd37a7a0ac | 32 | { |
nprobably | 0:4ebd37a7a0ac | 33 | // MAIN CODE HERE |
alansim | 2:10f92fa42985 | 34 | queue.call_every(100, read_potentiometer); |
alansim | 2:10f92fa42985 | 35 | while(1){ |
alansim | 2:10f92fa42985 | 36 | wait_ms(100); |
alansim | 2:10f92fa42985 | 37 | queue.dispatch(0); |
alansim | 2:10f92fa42985 | 38 | } |
nprobably | 0:4ebd37a7a0ac | 39 | } |