PT1 test

Dependencies:   mbed

Fork of AnalogIn-HelloWorld by Mbed

Committer:
runeleTanihata
Date:
Fri Nov 04 08:35:10 2016 +0000
Revision:
3:fd756d21b4c8
Parent:
2:8f81a97c83fb
[F303K8]change debug out(to USBTXRX)

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
runeleTanihata 2:8f81a97c83fb 20
runeleTanihata 2:8f81a97c83fb 21 #ifdef TARGET_SSCI824
runeleTanihata 2:8f81a97c83fb 22 Serial pc(USBTX,USBRX);
runeleTanihata 2:8f81a97c83fb 23 AnalogIn ain(P0_13);
runeleTanihata 2:8f81a97c83fb 24 DigitalOut dout(P0_16);
runeleTanihata 2:8f81a97c83fb 25 #endif
runeleTanihata 2:8f81a97c83fb 26
runeleTanihata 2:8f81a97c83fb 27 #ifdef TARGET_NUCLEO_F303K8
runeleTanihata 3:fd756d21b4c8 28 Serial pc(USBTX,USBRX);
runeleTanihata 2:8f81a97c83fb 29 AnalogIn ain(PA_7);
runeleTanihata 2:8f81a97c83fb 30 DigitalOut dout(PB_1);
runeleTanihata 2:8f81a97c83fb 31 #endif
runeleTanihata 2:8f81a97c83fb 32
runeleTanihata 2:8f81a97c83fb 33 void disablePullUp(void)
runeleTanihata 2:8f81a97c83fb 34 {
runeleTanihata 2:8f81a97c83fb 35 #ifdef TARGET_SSCI824
runeleTanihata 2:8f81a97c83fb 36 DigitalIn pin(P0_13);
runeleTanihata 2:8f81a97c83fb 37 #endif
runeleTanihata 2:8f81a97c83fb 38 #ifdef TARGET_NUCLEO_F303K8
runeleTanihata 2:8f81a97c83fb 39 DigitalIn pin(PA_7);
runeleTanihata 2:8f81a97c83fb 40 #endif
runeleTanihata 2:8f81a97c83fb 41 pin.mode(PullNone);
runeleTanihata 2:8f81a97c83fb 42 }
sam_grove 0:101a12a915c6 43
sam_grove 0:101a12a915c6 44 int main(void)
sam_grove 0:101a12a915c6 45 {
runeleTanihata 2:8f81a97c83fb 46 disablePullUp();
sam_grove 0:101a12a915c6 47 while (1) {
sam_grove 0:101a12a915c6 48 // test the voltage on the initialized analog pin
sam_grove 0:101a12a915c6 49 // and if greater than 0.3 * VCC set the digital pin
sam_grove 0:101a12a915c6 50 // to a logic 1 otherwise a logic 0
runeleTanihata 2:8f81a97c83fb 51 if(ain > 0.5f) {
sam_grove 0:101a12a915c6 52 dout = 1;
sam_grove 0:101a12a915c6 53 } else {
sam_grove 0:101a12a915c6 54 dout = 0;
sam_grove 0:101a12a915c6 55 }
runeleTanihata 2:8f81a97c83fb 56
sam_grove 0:101a12a915c6 57 // print the percentage and 16 bit normalized values
runeleTanihata 2:8f81a97c83fb 58 pc.printf("percentage: %3.3f%%\n", ain.read()*100.0f);
runeleTanihata 2:8f81a97c83fb 59 pc.printf("normalized: 0x%04X \n", ain.read_u16());
sam_grove 0:101a12a915c6 60 wait(0.2f);
sam_grove 0:101a12a915c6 61 }
sam_grove 0:101a12a915c6 62 }