Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@0:800b74bff4d2, 2017-04-03 (annotated)
- Committer:
- bangbh
- Date:
- Mon Apr 03 05:48:04 2017 +0000
- Revision:
- 0:800b74bff4d2
- Child:
- 1:d725cda6f61b
first commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| bangbh | 0:800b74bff4d2 | 1 | /* mbed Example Program |
| bangbh | 0:800b74bff4d2 | 2 | * Copyright (c) 2006-2014 ARM Limited |
| bangbh | 0:800b74bff4d2 | 3 | * |
| bangbh | 0:800b74bff4d2 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| bangbh | 0:800b74bff4d2 | 5 | * you may not use this file except in compliance with the License. |
| bangbh | 0:800b74bff4d2 | 6 | * You may obtain a copy of the License at |
| bangbh | 0:800b74bff4d2 | 7 | * |
| bangbh | 0:800b74bff4d2 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| bangbh | 0:800b74bff4d2 | 9 | * |
| bangbh | 0:800b74bff4d2 | 10 | * Unless required by applicable law or agreed to in writing, software |
| bangbh | 0:800b74bff4d2 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| bangbh | 0:800b74bff4d2 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| bangbh | 0:800b74bff4d2 | 13 | * See the License for the specific language governing permissions and |
| bangbh | 0:800b74bff4d2 | 14 | * limitations under the License. |
| bangbh | 0:800b74bff4d2 | 15 | */ |
| bangbh | 0:800b74bff4d2 | 16 | |
| bangbh | 0:800b74bff4d2 | 17 | #include "mbed.h" |
| bangbh | 0:800b74bff4d2 | 18 | |
| bangbh | 0:800b74bff4d2 | 19 | // Initialize a pins to perform analog input and digital output fucntions |
| bangbh | 0:800b74bff4d2 | 20 | AnalogIn ain(P30); |
| bangbh | 0:800b74bff4d2 | 21 | DigitalOut dout(LED1); |
| bangbh | 0:800b74bff4d2 | 22 | |
| bangbh | 0:800b74bff4d2 | 23 | int main(void) |
| bangbh | 0:800b74bff4d2 | 24 | { |
| bangbh | 0:800b74bff4d2 | 25 | Serial pc(USBTX,USBRX); |
| bangbh | 0:800b74bff4d2 | 26 | pc.baud(115200); |
| bangbh | 0:800b74bff4d2 | 27 | while (1) { |
| bangbh | 0:800b74bff4d2 | 28 | // test the voltage on the initialized analog pin |
| bangbh | 0:800b74bff4d2 | 29 | // and if greater than 0.3 * VCC set the digital pin |
| bangbh | 0:800b74bff4d2 | 30 | // to a logic 1 otherwise a logic 0 |
| bangbh | 0:800b74bff4d2 | 31 | if(ain > 0.3f) { |
| bangbh | 0:800b74bff4d2 | 32 | dout = 1; |
| bangbh | 0:800b74bff4d2 | 33 | } else { |
| bangbh | 0:800b74bff4d2 | 34 | dout = 0; |
| bangbh | 0:800b74bff4d2 | 35 | } |
| bangbh | 0:800b74bff4d2 | 36 | |
| bangbh | 0:800b74bff4d2 | 37 | // print the percentage and 16 bit normalized values |
| bangbh | 0:800b74bff4d2 | 38 | printf("percentage: %3.3f%%\n", ain.read()*100.0f); |
| bangbh | 0:800b74bff4d2 | 39 | printf("normalized: 0x%04X \n", ain.read_u16()); |
| bangbh | 0:800b74bff4d2 | 40 | wait(0.2f); |
| bangbh | 0:800b74bff4d2 | 41 | } |
| bangbh | 0:800b74bff4d2 | 42 | } |