DonghunKang
Dependencies: mbed Adafruit_GFX
main.cpp
- Committer:
- eins
- Date:
- 2019-10-27
- Revision:
- 2:3061fe655b7d
- Parent:
- 1:ae0b11ca17d1
- Child:
- 3:e7cab3f9facb
File content as of revision 2:3061fe655b7d:
#include "mbed.h" #include "Adafruit_SSD1306.h" // Adafruit_GFX library Serial pc(SERIAL_TX, SERIAL_RX); DigitalOut myled(LED1); DigitalOut redLed(PA_12); DigitalIn myButton(PC_13); DigitalIn exButton(PC_11); DigitalOut myAnalogOut(PA_4); BusOut my7Seg(PA_8, PA_9, PA_10, PC_9, PC_8, PC_7, PC_6, PA_11); // 8bit data // LSB, , MSB char val7Seg[16] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71}; char rxData[5]; bool flagRx = 0; #define TEST1 #ifdef TEST1 int main(void) { while (1) { // change the voltage on the digital output pin by 0.1 * VCC // and print what the measured voltage should be (assuming VCC = 3.3v) for (float n = 0.0f; n < 1.0f; n += 0.1f) { myAnalogOut = n; // myAnalogOut.write(n); pc.printf("output = %1.2f volts\n", myAnalogOut.read() * 3.3f); // turn on the led if the voltage is greater than 0.5f * VCC myled = (myAnalogOut > 0.5f) ? 1 : 0; wait(0.1); } } } #endif #ifdef TEST2 Ticker DACtimer; bool flagTimer = 0; void DACInt() { flagTimer = 1; } main() { // for 10kHz sine wave generation, it's needed to have // a sampling frequency in 10 times of that frequency, // or 100kHz -> 10us period DACtimer.attach_us(&DACInt, 10); float freq = 1000; // 1kHz = 1000Hz while(1) { if (1 == flagTimer) { flagTime = 0; myAnalogOut = sin(n*3.14/180.0)*0.5+0.5; n++; } } } #endif