Hiroki Tanihata
/
PT1_Test
PT1 test
Fork of AnalogIn-HelloWorld by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* mbed Example Program 00002 * Copyright (c) 2006-2014 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "mbed.h" 00018 00019 // Initialize a pins to perform analog input and digital output fucntions 00020 00021 #ifdef TARGET_SSCI824 00022 Serial pc(USBTX,USBRX); 00023 AnalogIn ain(P0_13); 00024 DigitalOut dout(P0_16); 00025 #endif 00026 00027 #ifdef TARGET_NUCLEO_F303K8 00028 Serial pc(USBTX,USBRX); 00029 AnalogIn ain(PA_7); 00030 DigitalOut dout(PB_1); 00031 #endif 00032 00033 void disablePullUp(void) 00034 { 00035 #ifdef TARGET_SSCI824 00036 DigitalIn pin(P0_13); 00037 #endif 00038 #ifdef TARGET_NUCLEO_F303K8 00039 DigitalIn pin(PA_7); 00040 #endif 00041 pin.mode(PullNone); 00042 } 00043 00044 int main(void) 00045 { 00046 disablePullUp(); 00047 while (1) { 00048 // test the voltage on the initialized analog pin 00049 // and if greater than 0.3 * VCC set the digital pin 00050 // to a logic 1 otherwise a logic 0 00051 if(ain > 0.5f) { 00052 dout = 1; 00053 } else { 00054 dout = 0; 00055 } 00056 00057 // print the percentage and 16 bit normalized values 00058 pc.printf("percentage: %3.3f%%\n", ain.read()*100.0f); 00059 pc.printf("normalized: 0x%04X \n", ain.read_u16()); 00060 wait(0.2f); 00061 } 00062 }
Generated on Thu Jul 21 2022 05:52:17 by 1.7.2