
AnalogIn-HelloWorld in WIZwiki-W7500
Dependencies: mbed
Fork of AnalogIn-HelloWorld_WIZwiki-W7500 by
Prerequisite
This Program is an example of how to get analog data with WIZwiki-W7500 board A0 Pin.
To implement this function, you need a Platform board only.
- WIZwiki-W7500 from WIZnet (Platform board)
Hardware Configuration
WIZwiki-W7500 Pin map
Initialize an analog pin
Initialize an A0 pin of WIZwiki-W7100 platform as an analog pin.
Read analog data from analog pin
Connect an analog device, such as a variable resistor, to a0 pin. And read analog data.
Software
ADC Pin initialization
main.cpp
AnalogIn ain(A0);
Read analog data and print to serial port
main.cpp
printf("percentage: %3.3f%%\n", ain.read()*100.0f);
main.cpp@3:c1650d8d13b4, 2015-06-22 (annotated)
- Committer:
- justinkim
- Date:
- Mon Jun 22 04:12:45 2015 +0000
- Revision:
- 3:c1650d8d13b4
- Parent:
- 2:da2772e498bf
in WIZwiki-W7500
Who changed what in which revision?
User | Revision | Line number | New 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 |
sam_grove | 0:101a12a915c6 | 20 | AnalogIn ain(A0); |
sam_grove | 0:101a12a915c6 | 21 | DigitalOut dout(LED1); |
sam_grove | 0:101a12a915c6 | 22 | |
sam_grove | 0:101a12a915c6 | 23 | int main(void) |
sam_grove | 0:101a12a915c6 | 24 | { |
justinkim | 2:da2772e498bf | 25 | Serial pc(USBTX,USBRX); |
justinkim | 2:da2772e498bf | 26 | pc.baud(115200); |
sam_grove | 0:101a12a915c6 | 27 | while (1) { |
sam_grove | 0:101a12a915c6 | 28 | // test the voltage on the initialized analog pin |
sam_grove | 0:101a12a915c6 | 29 | // and if greater than 0.3 * VCC set the digital pin |
sam_grove | 0:101a12a915c6 | 30 | // to a logic 1 otherwise a logic 0 |
sam_grove | 0:101a12a915c6 | 31 | if(ain > 0.3f) { |
sam_grove | 0:101a12a915c6 | 32 | dout = 1; |
sam_grove | 0:101a12a915c6 | 33 | } else { |
sam_grove | 0:101a12a915c6 | 34 | dout = 0; |
sam_grove | 0:101a12a915c6 | 35 | } |
sam_grove | 0:101a12a915c6 | 36 | |
sam_grove | 0:101a12a915c6 | 37 | // print the percentage and 16 bit normalized values |
sam_grove | 0:101a12a915c6 | 38 | printf("percentage: %3.3f%%\n", ain.read()*100.0f); |
sam_grove | 0:101a12a915c6 | 39 | printf("normalized: 0x%04X \n", ain.read_u16()); |
sam_grove | 0:101a12a915c6 | 40 | wait(0.2f); |
sam_grove | 0:101a12a915c6 | 41 | } |
sam_grove | 0:101a12a915c6 | 42 | } |