University of Plymouth - Stages 1, 2 and 3
/
Task442-FZ429ZI
Version for FZ420ZI
Fork of Task442 by
main.cpp
- Committer:
- noutram
- Date:
- 2019-09-18
- Revision:
- 3:36ab439835c7
- Parent:
- 2:6c9c8dfe36e6
- Child:
- 4:50e9ae883931
File content as of revision 3:36ab439835c7:
#include "mbed.h" //Function prototype void doSample1Hz(); //Global objects Serial pc(USBTX, USBRX); AnalogIn POT_ADC_In(A0); DigitalOut led1(LED1); DigitalOut led2(LED2); //Shared variables volatile static unsigned short sample16 = 0; //The ticker, used to sample data at a fixed rate Ticker t; //Main function int main() { //Set baud rate to 115200 pc.baud(115200); //Power on self test led1 = 1; led2 = 1; pc.printf("TESTING\n\r"); wait(1.0); led1 = 1; led2 = 1; pc.printf("DONE\n\r"); wait(1.0); //Set up the ticker - 100Hz t.attach(doSample1Hz, 1.0); while(1) { //Sleep sleep(); //READ ADC as an unsigned integer. //Shift right 4 bits (this is a 12bit ADC) & store in static global variable sample16 = POT_ADC_In.read_u16() >> 4; //Hardware debug to verify this is working led2 = !led2; //Displauy the sample in HEX pc.printf("ADC Value: %X\n", sample16); //Wait for 20 characters to clear wait(0.0014); } //end while(1) } //end main //ISR for the ticker - simply there to perform sampling void doSample1Hz() { //Toggle on board led led1 = !led1; }