DonghunKang

Dependencies:   mbed Adafruit_GFX

Revision:
2:3061fe655b7d
Parent:
1:ae0b11ca17d1
Child:
3:e7cab3f9facb
--- a/main.cpp	Wed Oct 16 04:48:38 2019 +0000
+++ b/main.cpp	Sun Oct 27 00:38:25 2019 +0000
@@ -6,6 +6,7 @@
 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
@@ -15,32 +16,53 @@
 char rxData[5];
 bool flagRx = 0;
 
-int main()
-{   
-    I2C     I2C_Oled(PB_7, PA_15);       // SDA, SCL
-    I2C_Oled.frequency(400000);     // 400kHz clock
-    
-    Adafruit_SSD1306_I2c    myOled(I2C_Oled, PA_1);    //  D2
+#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);
 
-    myOled.splash();      // logo output
-    myOled.display();
-    wait(0.5);
-    
-    myOled.clearDisplay();  // clear buffer     
-    myOled.printf("%u x %u OLED Display\r\n", myOled.width(), myOled.height());
-    myOled.display();       // show a image on the OLED
-    wait(1);
- 
-    uint16_t n = 0;
-    
+            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)
     {
-        myled = !myled;
+        if (1 == flagTimer)
+        {
+            flagTime = 0;
+            myAnalogOut = sin(n*3.14/180.0)*0.5+0.5;
+            n++;
+        }    
+    }       
+}
+#endif
 
-        myOled.clearDisplay();      
-        myOled.setTextCursor(1, 5);
-        myOled.printf("<<< UNIST DHE: %u >>>",n++);
-        myOled.display();
-        wait(0.1);
-    }
-}