University of Plymouth - Stages 1, 2 and 3
/
Task442-FZ429ZI
Version for FZ420ZI
Fork of Task442 by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 //Function prototype 00004 void doSample1Hz(); 00005 00006 //Global objects 00007 Serial pc(USBTX, USBRX); 00008 AnalogIn POT_ADC_In(A0); 00009 DigitalOut led1(LED1); 00010 DigitalOut led2(LED2); 00011 00012 //Shared variables 00013 volatile static unsigned short sample16 = 0; 00014 00015 //The ticker, used to sample data at a fixed rate 00016 Ticker t; 00017 00018 //Main function 00019 int main() 00020 { 00021 //Set baud rate to 115200 00022 pc.baud(115200); 00023 00024 //Power on self test 00025 led1 = 1; led2 = 1; 00026 pc.printf("TESTING\n\r"); 00027 wait(1.0); 00028 led1 = 1; led2 = 1; 00029 pc.printf("DONE\n\r"); 00030 wait(1.0); 00031 00032 //Set up the ticker - 1Hz 00033 t.attach(doSample1Hz, 1.0); 00034 00035 while(1) { 00036 00037 //Sleep 00038 sleep(); 00039 00040 //READ ADC as an unsigned integer. 00041 //Shift right 4 bits (this is a 12bit ADC) & store in static global variable 00042 sample16 = POT_ADC_In.read_u16() >> 4; 00043 00044 //Hardware debug to verify this is working 00045 led2 = !led2; 00046 00047 //Display the sample in HEX 00048 pc.printf("ADC Value: %X\n", sample16); 00049 //Wait for 20 characters to clear 00050 wait(0.0014); 00051 00052 } //end while(1) 00053 } //end main 00054 00055 //ISR for the ticker - simply there to perform sampling 00056 void doSample1Hz() { 00057 //Toggle on board led 00058 led1 = !led1; 00059 } 00060
Generated on Fri Jul 15 2022 16:52:53 by 1.7.2