mech / Mbed OS AnalogIn_HelloWorld

Fork of AnalogIn_HelloWorld by mbed_example

Committer:
isshikiyuya
Date:
Sat Nov 17 06:19:47 2018 +0000
Revision:
5:c22a0111045b
Parent:
4:e29502420eef
Child:
6:a78d4d502f81
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:101a12a915c6 1 /* mbed Example Program
sam_grove 0:101a12a915c6 2 * Copyright (c) 2006-2014 ARM Limited
sam_grove 0:101a12a915c6 3 *
sam_grove 0:101a12a915c6 4 * Licensed under the Apache License, Version 2.0 (the "License");
sam_grove 0:101a12a915c6 5 * you may not use this file except in compliance with the License.
sam_grove 0:101a12a915c6 6 * You may obtain a copy of the License at
sam_grove 0:101a12a915c6 7 *
sam_grove 0:101a12a915c6 8 * http://www.apache.org/licenses/LICENSE-2.0
sam_grove 0:101a12a915c6 9 *
sam_grove 0:101a12a915c6 10 * Unless required by applicable law or agreed to in writing, software
sam_grove 0:101a12a915c6 11 * distributed under the License is distributed on an "AS IS" BASIS,
sam_grove 0:101a12a915c6 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sam_grove 0:101a12a915c6 13 * See the License for the specific language governing permissions and
sam_grove 0:101a12a915c6 14 * limitations under the License.
sam_grove 0:101a12a915c6 15 */
sam_grove 0:101a12a915c6 16
sam_grove 0:101a12a915c6 17 #include "mbed.h"
sam_grove 0:101a12a915c6 18
sam_grove 0:101a12a915c6 19 // Initialize a pins to perform analog input and digital output fucntions
isshikiyuya 5:c22a0111045b 20 AnalogIn ain1(A3);
isshikiyuya 5:c22a0111045b 21 AnalogIn ain2(A4);
isshikiyuya 5:c22a0111045b 22 AnalogIn ain3(A5);
sam_grove 0:101a12a915c6 23
sam_grove 0:101a12a915c6 24 int main(void)
sam_grove 0:101a12a915c6 25 {
sam_grove 0:101a12a915c6 26 while (1) {
sam_grove 0:101a12a915c6 27 // test the voltage on the initialized analog pin
sam_grove 0:101a12a915c6 28 // and if greater than 0.3 * VCC set the digital pin
sam_grove 0:101a12a915c6 29 // to a logic 1 otherwise a logic 0
sam_grove 0:101a12a915c6 30
sam_grove 0:101a12a915c6 31 // print the percentage and 16 bit normalized values
isshikiyuya 4:e29502420eef 32 // printf("percentage: %3.3f%%\n", ain.read()*100.0f);
isshikiyuya 4:e29502420eef 33 // printf("normalized: 0x%04X \n", ain.read_u16());
isshikiyuya 5:c22a0111045b 34 printf("voltage ain1: %f V\n", ain1.read());
isshikiyuya 5:c22a0111045b 35 printf("voltage ain2: %f V\n", ain2.read());
isshikiyuya 5:c22a0111045b 36 printf("voltage ain3: %f V\n\n", ain3.read());
isshikiyuya 4:e29502420eef 37 wait(2);
sam_grove 0:101a12a915c6 38 }
sam_grove 0:101a12a915c6 39 }