Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 00003 DigitalOut dout1(LED1); 00004 DigitalOut dout2(LED2); 00005 DigitalOut dout3(LED3); 00006 DigitalOut dout4(LED4); 00007 AnalogIn ain(p15); 00008 // The sinewave is created on this pin 00009 AnalogOut aout(p18); 00010 00011 int main() 00012 { 00013 const double pi = 3.141592653589793238462; 00014 const double amplitude = 0.5f; 00015 const double offset = 65535/2; 00016 double rads = 0.0; 00017 uint16_t sample = 0; 00018 00019 while(1) { 00020 // sinewave output 00021 for (int i = 0; i < 360; i++) { 00022 rads = (pi * i) / 180.0f; 00023 sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset); 00024 aout.write_u16(sample); 00025 } 00026 00027 //Sharp IR sensor display 00028 if (ain.read() > 0.9f) //less than 7 cm 00029 { 00030 dout1 = 1; 00031 dout2 = 1; 00032 dout3 = 1; 00033 dout4 = 1; 00034 } 00035 else if (ain.read() > 0.68f && ain.read() <= 0.9f) //7-10 00036 { 00037 dout1 = 0; 00038 dout2 = 1; 00039 dout3 = 1; 00040 dout4 = 1; 00041 } 00042 else if (ain.read() > 0.53f && ain.read() <= 0.68f) //10-13 00043 { 00044 dout1 = 0; 00045 dout2 = 0; 00046 dout3 = 1; 00047 dout4 = 1; 00048 } 00049 else if (ain.read() > 0.45f && ain.read() <= 0.53f) //13-17 00050 { 00051 dout1 = 0; 00052 dout2 = 0; 00053 dout3 = 0; 00054 dout4 = 1; 00055 } 00056 else //greater than 17 00057 { 00058 00059 dout1 = 0; 00060 dout2 = 0; 00061 dout3 = 0; 00062 dout4 = 0; 00063 } 00064 } 00065 }
Generated on Wed Aug 31 2022 22:51:05 by
1.7.2