diff --git a/Homework/Homework4/Bluetooth/Bluetooth.ino b/Homework/Homework4/Bluetooth/Bluetooth.ino new file mode 100644 index 0000000..7673be4 --- /dev/null +++ b/Homework/Homework4/Bluetooth/Bluetooth.ino @@ -0,0 +1,38 @@ +#include "SoftwareSerial.h" + +const byte rx_connected = 11; +const byte tx_connected = 10; + +SoftwareSerial soft_serial(tx_connected, rx_connected); + +void setup() { + pinMode(tx_connected, INPUT); + pinMode(rx_connected, OUTPUT); + Serial.begin(9600); + soft_serial.begin(9600); +} + +void loop() { + if (Serial.available()) { + char ch = Serial.read(); + Serial.print(ch); + soft_serial.print(ch); + } + if (soft_serial.available()) { + char ch = soft_serial.read(); + Serial.print(ch); + soft_serial.print(ch); + } + Serial.println("A loop"); + // Serial.println("A loop"); + // if (soft_serial.availableForWrite()) { + // Serial.println("Available"); + // } + // else { + // Serial.println("Unavailable"); + // } + // if (Serial.availableForWrite()) { + // Serial.println("Can Write"); + // } + delay(1000); +} \ No newline at end of file diff --git a/Homework/Homework4/OLED/OLED.ino b/Homework/Homework4/OLED/OLED.ino new file mode 100644 index 0000000..794f1a2 --- /dev/null +++ b/Homework/Homework4/OLED/OLED.ino @@ -0,0 +1,43 @@ +#include "U8glib.h" + +U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE); // I2C / TWI + +void draw(void) { + // graphic commands to redraw the complete screen should be placed here + u8g.setFont(u8g_font_courR18); + //u8g.setFont(u8g_font_osb21); + u8g.drawStr( 0, 14, "Hello World!"); +} + +void setup(void) { + // flip screen, if required + // u8g.setRot180(); + + // set SPI backup if required + //u8g.setHardwareBackup(u8g_backup_avr_spi); + + // assign default color value + if ( u8g.getMode() == U8G_MODE_R3G3B2 ) { + u8g.setColorIndex(255); // white + } + else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) { + u8g.setColorIndex(3); // max intensity + } + else if ( u8g.getMode() == U8G_MODE_BW ) { + u8g.setColorIndex(1); // pixel on + } + else if ( u8g.getMode() == U8G_MODE_HICOLOR ) { + u8g.setHiColorByRGB(255,255,255); + } +} + +void loop(void) { + // picture loop + u8g.firstPage(); + do { + draw(); + } while( u8g.nextPage() ); + + // rebuild the picture after some delay + //delay(50); +} \ No newline at end of file