Code for driving 9x OLED displays and reding from an HX711 load cell aplifier.
Dependencies: Adafruit_GFX SPI_TFT_ILI9341 TFT_fonts hx711 mbed
Diff: main.cpp
- Revision:
- 3:6dcf74b20bed
- Parent:
- 2:c5f60c130f9a
- Child:
- 4:89541d91cef1
--- a/main.cpp Thu Feb 26 11:30:54 2015 +0000 +++ b/main.cpp Sun Mar 08 22:32:05 2015 +0000 @@ -14,12 +14,24 @@ #include "Adafruit_SSD1306.h" #include "Adafruit_GFX.h" #include "PinNames.h" +#include "SPI_TFT_ILI9341.h" +#include "string" +#include "Arial12x12.h" +#include "Arial24x23.h" +#include "Arial28x28.h" +#include "font_big.h" DigitalOut led1(LED1); DigitalOut led2(LED2); -#define MUX_MASK 0x0000000F -PortOut MuxPortOut(PortB, MUX_MASK); +BusOut MuxPortOut(PTB11, PTB2, PTB10, PTB3); + +DigitalOut LCD_LED(PTC3); // the TFT display has a backlight switch + +extern unsigned char p1[]; // the mbed logo +// the TFT is connected to SPI pin 5-7 +SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTD0, PTC4, PTE26,"TFT"); // mosi, miso, sck, cs, reset, dc + // an SPI sub-class that provides a constructed default class SPIPreInit : public SPI @@ -36,7 +48,7 @@ class I2CPreInit : public I2C { public: - I2CPreInit(PinName PTE0, PinName PTE1) : I2C(PTE0, PTE1) + I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl) { frequency(800000); start(); @@ -47,18 +59,18 @@ //SPIPreInit gSpi(p5,NC,p7); //Adafruit_SSD1306_Spi gOled1(gSpi,p26,p25,p24); -I2CPreInit gI2C(PTE0,PTE1); +I2CPreInit gI2C(I2C_SDA,I2C_SCL); //mux_SSD1306_I2c gOled1(gI2C,Reset_Pin,muxport, muxmask, 0, 0x78,64); -mux_SSD1306_I2c gOled1(gI2C,PTD1,MuxPortOut, 0, 0x78,64); -mux_SSD1306_I2c gOled2(gI2C,PTD1,MuxPortOut, 0, 0x7A,64); -mux_SSD1306_I2c gOled3(gI2C,PTD1,MuxPortOut, 1, 0x78,64); -//mux_SSD1306_I2c gOled4(gI2C,PTD1,MuxPortOut, 1, 0x7A,64); -mux_SSD1306_I2c gOled5(gI2C,PTD1,MuxPortOut, 2, 0x78,64); -mux_SSD1306_I2c gOled6(gI2C,PTD1,MuxPortOut, 2, 0x7A,64); -mux_SSD1306_I2c gOled7(gI2C,PTD1,MuxPortOut, 3, 0x78,64); -mux_SSD1306_I2c gOled8(gI2C,PTD1,MuxPortOut, 3, 0x7A,64); -//mux_SSD1306_I2c gOled9(gI2C,PTD1,MuxPortOut, 4, 0x78,64); +mux_SSD1306_I2c gOled1(gI2C,PTC16,MuxPortOut, 0, 0x78,64); +mux_SSD1306_I2c gOled2(gI2C,PTC16,MuxPortOut, 0, 0x7A,64); +mux_SSD1306_I2c gOled3(gI2C,PTC16,MuxPortOut, 1, 0x78,64); +mux_SSD1306_I2c gOled4(gI2C,PTC16,MuxPortOut, 1, 0x7A,64); +mux_SSD1306_I2c gOled5(gI2C,PTC16,MuxPortOut, 2, 0x78,64); +mux_SSD1306_I2c gOled6(gI2C,PTC16,MuxPortOut, 2, 0x7A,64); +mux_SSD1306_I2c gOled7(gI2C,PTC16,MuxPortOut, 3, 0x78,64); +mux_SSD1306_I2c gOled8(gI2C,PTC16,MuxPortOut, 3, 0x7A,64); +mux_SSD1306_I2c gOled9(gI2C,PTC16,MuxPortOut, 4, 0x78,64); @@ -76,10 +88,10 @@ gOled3.drawLine(0, 0, gOled3.width()-1, i, WHITE); gOled3.display(); } -// for (int16_t i=0; i<gOled4.width(); i+=4) { -// gOled4.drawLine(0, 0, i, gOled4.height()-1, WHITE); -// gOled4.display(); -// } + for (int16_t i=0; i<gOled4.width(); i+=4) { + gOled4.drawLine(0, 0, i, gOled4.height()-1, WHITE); + gOled4.display(); + } for (int16_t i=0; i<gOled5.width(); i+=4) { gOled5.drawLine(0, 0, i, gOled5.height()-1, WHITE); gOled5.display(); @@ -96,62 +108,142 @@ gOled8.drawLine(0, 0, i, gOled8.height()-1, WHITE); gOled8.display(); } -// for (int16_t i=0; i<gOled9.width(); i+=4) { -// gOled9.drawLine(0, 0, i, gOled9.height()-1, WHITE); -// gOled9.display(); -// } + for (int16_t i=0; i<gOled9.width(); i+=4) { + gOled9.drawLine(0, 0, i, gOled9.height()-1, WHITE); + gOled9.display(); + } } int main() -{ uint16_t x=0; +{ +// ILI9341 Test Routine + int i; + LCD_LED = 1; // backlight on + + TFT.claim(stdout); // send stdout to the TFT display + //TFT.claim(stderr); // send stderr to the TFT display + TFT.set_orientation(1); + TFT.background(Black); // set background to black + TFT.foreground(White); // set chars to white + TFT.cls(); // clear the screen + + //first show the 4 directions + TFT.set_orientation(0); + TFT.background(Black); + TFT.cls(); + + TFT.set_font((unsigned char*) Arial12x12); + TFT.locate(0,0); + TFT.printf(" Hello Mbed 0"); + TFT.set_orientation(1); + TFT.locate(0,0); + TFT.printf(" Hello Mbed 1"); + TFT.set_orientation(2); + TFT.locate(0,0); + TFT.printf(" Hello Mbed 2"); + TFT.set_orientation(3); + TFT.locate(0,0); + TFT.printf(" Hello Mbed 3"); + TFT.set_orientation(1); + TFT.set_font((unsigned char*) Arial24x23); + TFT.locate(50,100); + TFT.printf("TFT orientation"); + +// draw some graphics + TFT.cls(); + TFT.set_font((unsigned char*) Arial24x23); + TFT.locate(100,100); + TFT.printf("Graphic"); + + TFT.line(0,0,100,0,Green); + TFT.line(0,0,0,200,Green); + TFT.line(0,0,100,200,Green); + + TFT.rect(100,50,150,100,Red); + TFT.fillrect(180,25,220,70,Blue); + + TFT.circle(80,150,33,White); + TFT.fillcircle(160,190,20,Yellow); + + double s; + + for (i=0; i<320; i++) { + s =20 * sin((long double) i / 10 ); + TFT.pixel(i,100 + (int)s ,Red); + } + TFT.set_orientation(2); + TFT.set_font((unsigned char*) Arial24x23); + +/* // bigger text + TFT.foreground(White); + TFT.background(Blue); + TFT.cls(); + TFT.set_font((unsigned char*) Arial24x23); + TFT.locate(0,0); + TFT.printf("Different Fonts :"); + + TFT.set_font((unsigned char*) Neu42x35); + TFT.locate(0,30); + TFT.printf("Hello Mbed 1"); + TFT.set_font((unsigned char*) Arial24x23); + TFT.locate(20,80); + TFT.printf("Hello Mbed 2"); + TFT.set_font((unsigned char*) Arial12x12); + TFT.locate(35,120); + TFT.printf("Hello Mbed 3"); +*/ + + // start of OLED Code + uint16_t x=0; uint16_t y=65535; uint16_t a=16348; uint16_t b=49152; led1=1; led2=1; - gOled1.clearDisplay(); gOled2.clearDisplay(); gOled3.clearDisplay(); -// gOled4.clearDisplay(); + gOled4.clearDisplay(); gOled5.clearDisplay(); gOled6.clearDisplay(); gOled7.clearDisplay(); gOled8.clearDisplay(); -// gOled9.clearDisplay(); + gOled9.clearDisplay(); testdrawline(); gOled1.clearDisplay(); gOled2.clearDisplay(); gOled3.clearDisplay(); -// gOled4.clearDisplay(); + gOled4.clearDisplay(); gOled5.clearDisplay(); gOled6.clearDisplay(); gOled7.clearDisplay(); gOled8.clearDisplay(); -// gOled9.clearDisplay(); + gOled9.clearDisplay(); gOled1.printf(" Aqua Vega A \r\n\n\n\n", gOled1.width(), gOled1.height()); gOled2.printf(" Aqua Vega B \r\n\n\n\n", gOled2.width(), gOled2.height()); gOled3.printf(" Cannazyme \r\n\n\n\n", gOled3.width(), gOled3.height()); -// gOled4.printf(" Rhizotonic \r\n\n\n\n", gOled4.width(), gOled4.height()); + gOled4.printf(" Rhizotonic \r\n\n\n\n", gOled4.width(), gOled4.height()); gOled5.printf(" Aqua Flores A \r\n\n\n\n", gOled5.width(), gOled5.height()); gOled6.printf(" Aqua Flores B \r\n\n\n\n", gOled6.width(), gOled6.height()); gOled7.printf(" PK13/14 \r\n\n\n\n", gOled7.width(), gOled7.height()); gOled8.printf(" Cannaboost \r\n\n\n\n", gOled8.width(), gOled8.height()); -// gOled9.printf(" pH-Down \r\n\n\n\n", gOled9.width(), gOled9.height()); + gOled9.printf(" pH-Down \r\n\n\n\n", gOled9.width(), gOled9.height()); gOled1.setTextSize(2); gOled2.setTextSize(2); gOled3.setTextSize(2); + gOled4.setTextSize(2); gOled5.setTextSize(2); gOled6.setTextSize(2); gOled7.setTextSize(2); gOled8.setTextSize(2); + gOled9.setTextSize(2); while(1) @@ -161,11 +253,12 @@ gOled1.display(); gOled6.printf(" %uml\r",x); gOled6.display(); - led1 = 1; led2 = 0; gOled2.printf(" %uml\r",y); gOled2.display(); + gOled4.printf(" %uml\r",y); + gOled4.display(); gOled7.printf(" %uml\r",y); gOled7.display(); gOled3.printf(" %uml\r",a); @@ -174,13 +267,21 @@ gOled8.display(); gOled5.printf(" %uml\r",b); gOled5.display(); -// gOled9.printf(" %uml\r",b); -// gOled9.display(); + gOled9.printf(" %uml\r",b); + gOled9.display(); led2 = 1; x++; y--; a++; b--; + TFT.locate(10,100); + TFT.printf("A Value:%d",a); + TFT.locate(10,125); + TFT.printf("B Value:%d",b); + TFT.locate(10,150); + TFT.printf("X Value:%d",x); + TFT.locate(10,175); + TFT.printf("Y Value:%d",y); //wait(0.1); } }