Code for driving 9x OLED displays and reding from an HX711 load cell aplifier.

Dependencies:   Adafruit_GFX SPI_TFT_ILI9341 TFT_fonts hx711 mbed

main.cpp

Committer:
jimconner
Date:
2015-02-26
Revision:
2:c5f60c130f9a
Parent:
1:c09b25119427
Child:
3:6dcf74b20bed

File content as of revision 2:c5f60c130f9a:

/*
 *  Copyright (c) 2012 Neal Horman - http://www.wanlink.com
 *  
 *  License: MIT open source (http://opensource.org/licenses/MIT)
 *      Summary;
 *      Use / modify / distribute / publish it how you want and 
 *      if you use it, or don't, you can't hold me liable for how
 *      it does or doesn't work.
 *      If it doesn't work how you want, don't use it, or change
 *      it so that it does work.
 */
 
#include "mbed.h"
#include "Adafruit_SSD1306.h"
#include "Adafruit_GFX.h"
#include "PinNames.h"
 
DigitalOut led1(LED1);
DigitalOut led2(LED2);

#define MUX_MASK 0x0000000F
PortOut MuxPortOut(PortB, MUX_MASK);

// an SPI sub-class that provides a constructed default
class SPIPreInit : public SPI
{
public:
    SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk)
    {
        format(8,3);
        frequency(2000000);
    };
};
 
// an I2C sub-class that provides a constructed default
class I2CPreInit : public I2C
{
public:
    I2CPreInit(PinName PTE0, PinName PTE1) : I2C(PTE0, PTE1)
    {
        frequency(800000);
        start();
        wait(0.1); // needed so that the displays initialise properly at power-on.
    };
};
 
//SPIPreInit gSpi(p5,NC,p7);
//Adafruit_SSD1306_Spi gOled1(gSpi,p26,p25,p24);
 
I2CPreInit gI2C(PTE0,PTE1);
//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);




void testdrawline() {
    for (int16_t i=0; i<gOled1.width(); i+=4) {
        gOled1.drawLine(0, 0, i, gOled1.height()-1, WHITE);
        gOled1.display();
    }
    for (int16_t i=0; i<gOled2.height(); i+=4) {
        gOled2.drawLine(0, 0, gOled2.width()-1, i, WHITE);
        gOled2.display();
    }
    for (int16_t i=0; i<gOled3.height(); i+=4) {
        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<gOled5.width(); i+=4) {
        gOled5.drawLine(0, 0, i, gOled5.height()-1, WHITE);
        gOled5.display();
    }
    for (int16_t i=0; i<gOled6.width(); i+=4) {
        gOled6.drawLine(0, 0, i, gOled6.height()-1, WHITE);
        gOled6.display();
    }
    for (int16_t i=0; i<gOled7.width(); i+=4) {
        gOled7.drawLine(0, 0, i, gOled7.height()-1, WHITE);
        gOled7.display();
    }
    for (int16_t i=0; i<gOled8.width(); i+=4) {
        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();
//    }

}


 
int main()
{   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();
    gOled5.clearDisplay();    
    gOled6.clearDisplay();    
    gOled7.clearDisplay();    
    gOled8.clearDisplay();    
//    gOled9.clearDisplay();    
    
    testdrawline();

    gOled1.clearDisplay();
    gOled2.clearDisplay();
    gOled3.clearDisplay();
//    gOled4.clearDisplay();
    gOled5.clearDisplay();
    gOled6.clearDisplay();
    gOled7.clearDisplay();
    gOled8.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());
    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());
    gOled1.setTextSize(2);
    gOled2.setTextSize(2);
    gOled3.setTextSize(2);
    gOled5.setTextSize(2);
    gOled6.setTextSize(2);
    gOled7.setTextSize(2);
    gOled8.setTextSize(2);

    
    while(1)
    {
        led1 = 0;
        gOled1.printf("  %uml\r",x);
        gOled1.display();
        gOled6.printf("  %uml\r",x);
        gOled6.display();

        led1 = 1;
        led2 = 0;
        gOled2.printf("  %uml\r",y);
        gOled2.display();
        gOled7.printf("  %uml\r",y);
        gOled7.display();
        gOled3.printf("  %uml\r",a);
        gOled3.display();
        gOled8.printf("  %uml\r",a);
        gOled8.display();
        gOled5.printf("  %uml\r",b);
        gOled5.display();
//        gOled9.printf("  %uml\r",b);
//        gOled9.display();
        led2 = 1;
        x++;
        y--;
        a++;
        b--;
        //wait(0.1);
    }
}