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.
Diff: main.cpp
- Revision:
- 0:cb63da12fdcc
diff -r 000000000000 -r cb63da12fdcc main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Nov 26 04:49:45 2019 +0000
@@ -0,0 +1,147 @@
+#include "Adafruit_SSD1306.h"
+
+//---
+#include "mbed.h"
+
+AnalogIn analog_value(A0);
+DigitalOut led(LED1);
+//---
+
+static char font[][10] = {
+#if 0
+{0x10,0x10,0x54,0x52,0x92,0x10,0x30,0x00}, // 小
+{0x3c,0x24,0x58,0x10,0x3e,0xd2,0x1e,0x00}, // 名
+{0x10,0xfe,0x10,0x38,0x54,0x92,0x10,0x00}, // 木
+{0x98,0x1c,0xa8,0x3e,0x80,0x9c,0x9c,0x00}, // 浩
+{0x10,0x7c,0xfe,0x28,0xfe,0x7c,0x10,0x00}, // 幸
+{0x7e,0x40,0x7c,0x42,0x02,0x42,0x3c,0x00}, // 5
+{0x3c,0x42,0x02,0x1c,0x02,0x42,0x3c,0x00}, // 3
+{0x08,0xfe,0x08,0x0c,0x18,0xe8,0x18,0x00}, // 才
+#endif
+#if 1
+{0x08,0xfe,0x08,0x0c,0x18,0xe8,0x18,0x00}, // 才
+{0x3c,0x42,0x02,0x1c,0x02,0x42,0x3c,0x00}, // 3
+{0x7e,0x40,0x7c,0x42,0x02,0x42,0x3c,0x00}, // 5
+{0x10,0x7c,0xfe,0x28,0xfe,0x7c,0x10,0x00}, // 幸
+{0x98,0x1c,0xa8,0x3e,0x80,0x9c,0x9c,0x00}, // 浩
+{0x10,0xfe,0x10,0x38,0x54,0x92,0x10,0x00}, // 木
+{0x3c,0x24,0x58,0x10,0x3e,0xd2,0x1e,0x00}, // 名
+{0x10,0x10,0x54,0x52,0x92,0x10,0x30,0x00}, // 小
+#endif
+};
+
+
+// OLEDとの通信に使用するI2Cオブジェクトを生成
+I2C i2c(PC_1, PC_0);
+
+// OLED制御クラスのインスタンス化
+uint8_t i2cAddress = SSD_I2C_ADDRESS;
+uint8_t rawHeight = 64;
+uint8_t rawWidth = 128;
+
+Adafruit_SSD1306_I2c oled(i2c,PB_0, i2cAddress, rawHeight, rawWidth);
+
+unsigned int m_z=12434,m_w=33254;
+unsigned int rnd() {
+ m_z = 36969 * (m_z & 65535) + (m_z >>16);
+ m_w = 18000 * (m_w & 65535) + (m_w >>16);
+ return ((m_z <<16) + m_w);
+}
+
+int main() {
+ uint16_t x=0;
+ uint16_t x1, y1, w, h;
+ i2c.frequency(1000000);
+ oled.clearDisplay();
+
+//---
+ float meas_r;
+ float meas_v;
+ char str[100];
+ // printf("\nAnalogIn example\n");
+
+ while(1) {
+
+ meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range)
+ meas_v = meas_r * 3300; // Converts value in the 0V-3.3V range
+
+ sprintf( str, "%f = %.0f mV", meas_r, meas_v);
+ oled.setTextCursor(0,0);
+ oled.printf( str );
+ oled.display();
+ // Display values
+ // printf("measure = %f = %.0f mV\n", meas_r, meas_v);
+
+ // LED is ON is the value is below 1V
+ if (meas_v < 1000) {
+ led = 1; // LED ON
+ } else {
+ led = 0; // LED OFF
+ }
+
+ wait(0.5); // 1 second
+ }
+//---
+
+
+// oled.printf("Onagi Hiropyuki.\r\n");
+// oled.printf("%ux%u OLED Display\r\n\r\n", oled.width(), oled.height());
+if(1){
+ while(1) {
+ for (int i=0 ; i<120 ; i+=1 ) {
+ //oled.clearDisplay();
+ oled.drawBitmap(i, 0, (uint8_t *)font, 10, 64, 1);
+ oled.display();
+ oled.drawBitmap(i, 0, (uint8_t *)font, 10, 64, 0);
+
+ }
+ for (int i=120 ; i>0 ; i-=1 ) {
+ //oled.clearDisplay();
+ oled.drawBitmap(i, 0, (uint8_t *)font, 10, 64, 1);
+ oled.display();
+ oled.drawBitmap(i, 0, (uint8_t *)font, 10, 64, 0);
+ }
+ }
+ return 0;
+
+}
+
+ oled.drawRect( 0,0,127,63,1 );
+
+ while(1)
+ {
+ x++;
+ x1 = rnd() % 128;
+ y1 = rnd() % 64;
+ w = rnd() % (128 - x1);
+ h = rnd() % (64 - y1);
+ if ( x % 2 ) {
+ //oled.drawRect( x1, y1, w, h, 1 );
+ oled.drawBitmap(x1, y1, (uint8_t *)font, 82, 8, 1);
+ } else {
+ oled.drawCircle( x1, y1, w, 1 );
+ }
+
+ oled.display();
+ if ( x > 100 ) {
+ x = 0;
+ }
+ wait(0.5);
+ oled.clearDisplay();
+ }
+}
+
+/*
+#include "mbed.h"
+
+DigitalOut myled(LED1);
+
+int main() {
+ while(1) {
+ myled = 1; // LED is ON
+ wait(0.2); // 200 ms
+ myled = 0; // LED is OFF
+ wait(1.0); // 1 sec
+ }
+}
+*/
\ No newline at end of file