コード例 #1
0
void Adafruit_SSD1306::display(void) {
  ssd1306_command(SSD1306_COLUMNADDR);
  ssd1306_command(0);   // Column start address (0 = reset)
  ssd1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset)

  ssd1306_command(SSD1306_PAGEADDR);
  ssd1306_command(0); // Page start address (0 = reset)
  #if SSD1306_LCDHEIGHT == 64
    ssd1306_command(7); // Page end address
  #endif
  #if SSD1306_LCDHEIGHT == 32
    ssd1306_command(3); // Page end address
  #endif
  #if SSD1306_LCDHEIGHT == 16
    ssd1306_command(1); // Page end address
  #endif

    // I2C
    for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
      // send a bunch of data in one xmission
      Wire.beginTransmission(_i2caddr);
      WIRE_WRITE(0x40);
      for (uint8_t x=0; x<16; x++) {
  WIRE_WRITE(buffer[i]);
  i++;
      }
      i--;
      Wire.endTransmission();
    }
}
コード例 #2
0
ファイル: SH1106.cpp プロジェクト: Defragster/MicrOledPro
void LCD_SH1106::WriteCommand(unsigned char ins)
{
  Wire.beginTransmission(I2C_ADDR);//0x78 >> 1
  WIRE_WRITE(0x00);//0x00
  WIRE_WRITE(ins);
  Wire.endTransmission();
}
コード例 #3
0
ファイル: SH1106.cpp プロジェクト: Defragster/MicrOledPro
void LCD_SH1106::clear(byte x, byte y, byte width, byte height)
{
    WriteCommand(SSD1306_SETLOWCOLUMN | 0x0);  // low col = 0
    WriteCommand(SSD1306_SETHIGHCOLUMN | 0x0);  // hi col = 0
    WriteCommand(SSD1306_SETSTARTLINE | 0x0); // line #0

    height >>= 3;
    width >>= 3;
    y >>= 3;
#ifdef TWBR
    uint8_t twbrbackup = TWBR;
    TWBR = 18; // upgrade to 400KHz!
#endif
    for (byte i = 0; i < height; i++) {
      // send a bunch of data in one xmission
        WriteCommand(0xB0 + i + y);//set page address
        WriteCommand((x + 2) & 0xf);//set lower column address
        WriteCommand(0x10 | (x >> 4));//set higher column address

        for(byte j = 0; j < 8; j++){
            Wire.beginTransmission(I2C_ADDR);
            WIRE_WRITE(0x40);
            for (byte k = 0; k < width; k++) {
                WIRE_WRITE(0);
            }
            Wire.endTransmission();
        }
    }
#ifdef TWBR
    TWBR = twbrbackup;
#endif
    setCursor(0, 0);
}
コード例 #4
0
void Adafruit_SSD1306::ssd1306_data(uint8_t c) {
  if (sid != -1)
  {
    // SPI
#ifdef PortReg
    *csport |= cspinmask;
    *dcport |= dcpinmask;
    *csport &= ~cspinmask;
#else
    digitalWrite(cs, HIGH);
    digitalWrite(dc, HIGH);
    digitalWrite(cs, LOW);
#endif
    fastSPIwrite(c);
#ifdef PortReg
    *csport |= cspinmask;
#else
    digitalWrite(cs, HIGH);
#endif
  }
  else
  {
    // I2C
    uint8_t control = 0x40;   // Co = 0, D/C = 1
    Wire.beginTransmission(_i2caddr);
    WIRE_WRITE(control);
    WIRE_WRITE(c);
    Wire.endTransmission();
  }
}
コード例 #5
0
void ESP_SSD1306::ssd1306_command(uint8_t c) { 
  if (sid != -1)
  {
    // SPI
    digitalWrite(cs, HIGH);		//uncommented for ESP8266 compatibility
//    *csport |= cspinmask;		//commented for ESP8266 compatibility
    digitalWrite(dc, LOW);		//uncommented for ESP8266 compatibility
//    *dcport &= ~dcpinmask;	//commented for ESP8266 compatibility
    digitalWrite(cs, LOW);		//uncommented for ESP8266 compatibility
//    *csport &= ~cspinmask;	//commented for ESP8266 compatibility
    fastSPIwrite(c);
    digitalWrite(cs, HIGH);		//uncommented for ESP8266 compatibility
//    *csport |= cspinmask;		//commented for ESP8266 compatibility
  }
  else
  {
    // I2C
    uint8_t control = 0x00;   // Co = 0, D/C = 0
    Wire.beginTransmission(_i2caddr);
    WIRE_WRITE(control);
    WIRE_WRITE(c);
    Wire.endTransmission();
    yield();
  }
}
コード例 #6
0
void SRF02::update()
{
	if (interval == 0)
	{
		return;
	}

	if (rangingTriggered && millis() > nextRead)
	{
		for (SRF02 *i = first; i != 0; i = i->next)
		{
			Wire.beginTransmission(i->deviceId);
			WIRE_WRITE(2);
			Wire.endTransmission();
			Wire.requestFrom(i->deviceId, (uint8_t) 2);
			i->value = ((unsigned long) WIRE_READ()) << 8;
			i->value += (unsigned long) WIRE_READ();
		}
		rangingTriggered = false;
	}

	if (millis() > nextRequest)
	{
		for (SRF02 *i = first; i != 0; i = i->next)
		{
			Wire.beginTransmission(i->deviceId);
			WIRE_WRITE((uint8_t) 0);
			WIRE_WRITE(i->mode);
			Wire.endTransmission();
		}
		nextRead = millis() + READ_DURATION;
		nextRequest = millis() + interval;
		rangingTriggered = true;
	}
}
コード例 #7
0
ファイル: SH1106.cpp プロジェクト: Defragster/MicrOledPro
void LCD_SH1106::WriteData(unsigned char dat)
{
  Wire.beginTransmission(I2C_ADDR);//0x78 >> 1
  WIRE_WRITE(0x40);//0x40
  WIRE_WRITE(dat);
  Wire.endTransmission();
}
コード例 #8
0
ファイル: Adafruit_SSD1306.cpp プロジェクト: 0xPIT/Sming
void Adafruit_SSD1306::display(void) {
  ssd1306_command(SSD1306_COLUMNADDR);
  ssd1306_command(0);   // Column start address (0 = reset)
  ssd1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset)

  ssd1306_command(SSD1306_PAGEADDR);
  ssd1306_command(0); // Page start address (0 = reset)
  #if SSD1306_LCDHEIGHT == 64
    ssd1306_command(7); // Page end address
  #endif
  #if SSD1306_LCDHEIGHT == 32
    ssd1306_command(3); // Page end address
  #endif
  #if SSD1306_LCDHEIGHT == 16
    ssd1306_command(1); // Page end address
  #endif

  if (sid != -1)
  {
    // SPI
    *csport |= cspinmask;
    *dcport |= dcpinmask;
    *csport &= ~cspinmask;

    for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
      fastSPIwrite(buffer[i]);
      //ssd1306_data(buffer[i]);
    }
    *csport |= cspinmask;
  }
  else
  {
    // save I2C bitrate
#if !defined(__SAM3X8E__) && !defined(__ESP8266_EX__)
    uint8_t twbrbackup = TWBR;
    TWBR = 12; // upgrade to 400KHz!
#endif

    //Serial.println(TWBR, DEC);
    //Serial.println(TWSR & 0x3, DEC);

    // I2C
    for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
      // send a bunch of data in one xmission
      Wire.beginTransmission(_i2caddr);
      WIRE_WRITE(0x40);
      for (uint8_t x=0; x<16; x++) {
  WIRE_WRITE(buffer[i]);
  i++;
      }
      i--;
      Wire.endTransmission();
    }
#if !defined(__SAM3X8E__) && !defined(__ESP8266_EX__)
    TWBR = twbrbackup;
#endif
  }
}
コード例 #9
0
void Adafruit_SSD1306::ssd1306_data(uint8_t c) {
    // I2C
    uint8_t control = 0x40;   // Co = 0, D/C = 1
    Wire.beginTransmission(_i2caddr);
    WIRE_WRITE(control);
    WIRE_WRITE(c);
    Wire.endTransmission();
  
}
コード例 #10
0
void Adafruit_SSD1306::ssd1306_command(uint8_t c0, uint8_t c1, uint8_t c2) {
  uint8_t buff[4] ;
  
  buff[0] = 0x00;
  buff[1] = c0;
  buff[2] = c1;
  buff[3] = c2;

  if (sid != -1)
  {
    // SPI
    //digitalWrite(cs, HIGH);
    *csport |= cspinmask;
    //digitalWrite(dc, LOW);
    *dcport &= ~dcpinmask;
    //digitalWrite(cs, LOW);
    *csport &= ~cspinmask;
    fastSPIwrite(c0);
    fastSPIwrite(c1);
    fastSPIwrite(c2);
    //digitalWrite(cs, HIGH);
    *csport |= cspinmask;
  }
  else
  {
    // I2C
    //uint8_t control = 0x00;   // Co = 0, D/C = 0
    Wire.beginTransmission(_i2caddr);
    //WIRE_WRITE(control);
    WIRE_WRITE(buff, sizeof(buff));
    Wire.endTransmission();
  }
}
コード例 #11
0
unsigned int CMPS03::read ()
{
	Wire.beginTransmission(deviceId);
	WIRE_WRITE((uint8_t) 2);
	Wire.endTransmission();
	delay(1);
	Wire.requestFrom(deviceId, (uint8_t) 2);
	unsigned int value = ((unsigned int) WIRE_READ()) << 8;
	value = value + ((unsigned int) WIRE_READ());
	return value;
}
コード例 #12
0
ファイル: Adafruit_SSD1306.cpp プロジェクト: 0xPIT/Sming
void Adafruit_SSD1306::ssd1306_command(uint8_t c) { 
  if (sid != -1)
  {
    // SPI
    //digitalWrite(cs, HIGH);
    *csport |= cspinmask;
    //digitalWrite(dc, LOW);
    *dcport &= ~dcpinmask;
    //digitalWrite(cs, LOW);
    *csport &= ~cspinmask;
    fastSPIwrite(c);
    //digitalWrite(cs, HIGH);
    *csport |= cspinmask;
  }
  else
  {
    // I2C
    uint8_t control = 0x00;   // Co = 0, D/C = 0
    Wire.beginTransmission(_i2caddr);
    WIRE_WRITE(control);
    WIRE_WRITE(c);
    Wire.endTransmission();
  }
}
コード例 #13
0
void Adafruit_SH1106::SH1106_data(uint8_t c) {
  if (sid != -1)
  {
    // SPI
    //digitalWrite(cs, HIGH);
    *csport |= cspinmask;
    //digitalWrite(dc, HIGH);
    *dcport |= dcpinmask;
    //digitalWrite(cs, LOW);
    *csport &= ~cspinmask;
    fastSPIwrite(c);
    //digitalWrite(cs, HIGH);
    *csport |= cspinmask;
  }
  else
  {
    // I2C
    uint8_t control = 0x40;   // Co = 0, D/C = 1
    Wire.beginTransmission(_i2caddr);
    WIRE_WRITE(control);
    WIRE_WRITE(c);
    Wire.endTransmission();
  }
}
コード例 #14
0
void SRF02::configureDeviceId(uint8_t currentDeviceId, uint8_t newDeviceId)
{
	Wire.beginTransmission(currentDeviceId);
	WIRE_WRITE((uint8_t) 0);
	WIRE_WRITE((uint8_t) 0xA0);
	Wire.endTransmission();
	Wire.beginTransmission(currentDeviceId);
	WIRE_WRITE((uint8_t) 0);
	WIRE_WRITE((uint8_t) 0xAA);
	Wire.endTransmission();
	Wire.beginTransmission(currentDeviceId);
	WIRE_WRITE((uint8_t) 0);
	WIRE_WRITE((uint8_t) 0xA5);
	Wire.endTransmission();
	Wire.beginTransmission(currentDeviceId);
	WIRE_WRITE((uint8_t) 0);
	WIRE_WRITE(newDeviceId << 1);
	Wire.endTransmission();
}
コード例 #15
0
void ESP_SSD1306::display(void) {
  ssd1306_command(SSD1306_COLUMNADDR);
  ssd1306_command(0);   // Column start address (0 = reset)
  ssd1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset)

  ssd1306_command(SSD1306_PAGEADDR);
  ssd1306_command(0); // Page start address (0 = reset)
  #if SSD1306_LCDHEIGHT == 64
    ssd1306_command(7); // Page end address
  #endif
  #if SSD1306_LCDHEIGHT == 32
    ssd1306_command(3); // Page end address
  #endif
  #if SSD1306_LCDHEIGHT == 16
    ssd1306_command(1); // Page end address
  #endif

  if (sid != -1)
  {
	// SPI
    digitalWrite(cs, HIGH);		//added for ESP8266 compatibility
//	*csport |= cspinmask;		//commented for ESP8266 compatibility
    digitalWrite(dc, HIGH);		//added for ESP8266 compatibility
//	*dcport |= dcpinmask;		//commented for ESP8266 compatibility
    digitalWrite(cs, LOW);		//added for ESP8266 compatibility
//	*csport &= ~cspinmask;		//commented for ESP8266 compatibility

	for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
	  fastSPIwrite(buffer[i]);
      //ssd1306_data(buffer[i]);
	}
    digitalWrite(cs, HIGH);		//added for ESP8266 compatibility
//	*csport |= cspinmask;		//commented for ESP8266 compatibility
  }
  else
  {
    // save I2C bitrate
#ifndef __SAM3X8E__
//    uint8_t twbrbackup = TWBR;			//commented for ESP8266 compatibility
//    TWBR = 12; // upgrade to 400KHz!		//commented for ESP8266 compatibility
#endif

    //Serial.println(TWBR, DEC);
    //Serial.println(TWSR & 0x3, DEC);

    // I2C
    for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
      // send a bunch of data in one xmission
      Wire.beginTransmission(_i2caddr);
      WIRE_WRITE(0x40);
      for (uint8_t x=0; x<16; x++) {
  WIRE_WRITE(buffer[i]);
  i++;
      }
      i--;
      Wire.endTransmission();
      yield();
    }
#ifndef __SAM3X8E__
//    TWBR = twbrbackup;					//commented for ESP8266 compatibility
#endif
  }
}
コード例 #16
0
void Adafruit_SH1106::display(void) {
	SH1106_command(SH1106_SETLOWCOLUMN | 0x0);  // low col = 0
	SH1106_command(SH1106_SETHIGHCOLUMN | 0x0);  // hi col = 0
	SH1106_command(SH1106_SETSTARTLINE | 0x0); // line #0

  if (sid != -1)
  {
    // SPI
    *csport |= cspinmask;
    *dcport |= dcpinmask;
    *csport &= ~cspinmask;

    for (uint16_t i=0; i<(SH1106_LCDWIDTH*SH1106_LCDHEIGHT/8); i++) {
      fastSPIwrite(buffer[i]);
      //SH1106_data(buffer[i]);
    }
    *csport |= cspinmask;
  }
  else
  {
    // save I2C bitrate
#ifndef __SAM3X8E__
    uint8_t twbrbackup = TWBR;
    TWBR = 12; // upgrade to 400KHz!
#endif

    //Serial.println(TWBR, DEC);
    //Serial.println(TWSR & 0x3, DEC);
	
	byte x=0;
	byte y=0;
	int ind=0;

    // I2C
/*     for (uint16_t i=0; i<(SH1106_LCDWIDTH*SH1106_LCDHEIGHT/8); i++) { //1024
      // send a bunch of data in one xmission
      Wire.beginTransmission(_i2caddr);
      WIRE_WRITE(0x40);
      for (uint8_t x=0; x<16; x++) {
		  WIRE_WRITE(buffer[i]);
		  i++;
      }
      i--;
      Wire.endTransmission();
    } */
	
	for (byte i = 0; i < 8; i++) { //8
      // send a bunch of data in one xmission
        SH1106_command(0xB0 + i + y);//set page address
        SH1106_command((x + 2) & 0xf);//set lower column address
        SH1106_command(0x10 | (x >> 4));//set higher column address

        for(byte j = 0; j < 8; j++){
            Wire.beginTransmission(_i2caddr);
            Wire.write(0x40);
            for (byte k = 0; k < 16; k++) { //16
                WIRE_WRITE(buffer[ind]);
				ind++;
            }
            Wire.endTransmission();
        }
    }
	
#ifndef __SAM3X8E__
    TWBR = twbrbackup;
#endif
  }
}
コード例 #17
0
ファイル: SH1106.cpp プロジェクト: Defragster/MicrOledPro
size_t LCD_SH1106::write(uint8_t c)
{
    if (c == '\n') {
        setCursor(0, m_row + ((m_font == FONT_SIZE_SMALL) ? 1 : 2));
        return 1;
    } else if (c == '\r') {
        m_col = 0;
        return 1;
    }

#ifdef TWBR
    uint8_t twbrbackup = TWBR;
    TWBR = 18; // upgrade to 400KHz!
#endif
#ifndef MEMORY_SAVING
    if (m_font == FONT_SIZE_SMALL) {
#endif
        Wire.beginTransmission(I2C_ADDR);
        WIRE_WRITE(0x40);
        if (c > 0x20 && c < 0x7f) {
            c -= 0x21;
            for (byte i = 0; i < 5; i++) {
                byte d = pgm_read_byte(&font5x8[c][i]);
                WIRE_WRITE(d);
                if (m_flags & FLAG_PIXEL_DOUBLE_H) WIRE_WRITE(d);
            }
            WIRE_WRITE(0);
        } else {
            for (byte i = (m_flags & FLAG_PIXEL_DOUBLE_H) ? 11 : 6; i > 0; i--) {
                WIRE_WRITE(0);
            }
        }
        Wire.endTransmission();
        m_col += (m_flags & FLAG_PIXEL_DOUBLE_H) ? 11 : 6;
        if (m_col >= 128) {
            m_col = 0;
            m_row ++;
        }
#ifndef MEMORY_SAVING
    } else {
        if (c > 0x20 && c < 0x7f) {
            c -= 0x21;

            WriteCommand(0xB0 + m_row);//set page address
            WriteCommand(m_col & 0xf);//set lower column address
            WriteCommand(0x10 | (m_col >> 4));//set higher column address

            Wire.beginTransmission(I2C_ADDR);
            WIRE_WRITE(0x40);
            for (byte i = 0; i <= 14; i += 2) {
                byte d = pgm_read_byte(&font8x16_terminal[c][i]);
                WIRE_WRITE(d);
                if (m_flags & FLAG_PIXEL_DOUBLE_H) WIRE_WRITE(d);
            }
            Wire.endTransmission();

            WriteCommand(0xB0 + m_row + 1);//set page address
            WriteCommand(m_col & 0xf);//set lower column address
            WriteCommand(0x10 | (m_col >> 4));//set higher column address

            Wire.beginTransmission(I2C_ADDR);
            WIRE_WRITE(0x40);
            for (byte i = 1; i <= 15; i += 2) {
                byte d = pgm_read_byte(&font8x16_terminal[c][i]);
                WIRE_WRITE(d);
                if (m_flags & FLAG_PIXEL_DOUBLE_H) WIRE_WRITE(d);
            }
            Wire.endTransmission();
        } else {
コード例 #18
0
void Adafruit_SSD1306::display(void) {
  ssd1306_command(SSD1306_COLUMNADDR);
 #if SSD1306_LCDWIDTH == 64 && SSD1306_LCDHEIGHT == 48
    ssd1306_command(32);
    ssd1306_command(32 + SSD1306_LCDWIDTH - 1);
  #else
    ssd1306_command(0);   // Column start address (0 = reset)
    ssd1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset)
#endif
  ssd1306_command(SSD1306_PAGEADDR);
  ssd1306_command(0); // Page start address (0 = reset)
  ssd1306_command((SSD1306_LCDHEIGHT / 8) - 1); // Page end address

  if (sid != -1)
  {
    // SPI
#ifdef HAVE_PORTREG
    *csport |= cspinmask;
    *dcport |= dcpinmask;
    *csport &= ~cspinmask;
#else
    digitalWrite(cs, HIGH);
    digitalWrite(dc, HIGH);
    digitalWrite(cs, LOW);
#endif

    for (uint16_t i=0; i<(SSD1306_FRAMEBUFFER); i++) {
      fastSPIwrite(buffer[i]);
    }
#ifdef HAVE_PORTREG
    *csport |= cspinmask;
#else
    digitalWrite(cs, HIGH);
#endif
  }
  else
  {
    // save I2C bitrate
#ifdef TWBR
    uint8_t twbrbackup = TWBR;
    TWBR = 12; // upgrade to 400KHz!
#endif

    //Serial.println(TWBR, DEC);
    //Serial.println(TWSR & 0x3, DEC);

    // I2C
    for (uint16_t i=0; i<(SSD1306_FRAMEBUFFER); i++) {
      // send a bunch of data in one xmission
      Wire.beginTransmission(_i2caddr);
      WIRE_WRITE(0x40);
      for (uint8_t x=0; x<16; x++) {
        WIRE_WRITE(buffer[i]);
        i++;
      }
      i--;
      Wire.endTransmission();
    }
#ifdef TWBR
    TWBR = twbrbackup;
#endif
  }
}
コード例 #19
0
// Slave event handler
void Peggy2_Slave_onRequest(){
  uint8_t i;
  WIRE_WRITE((uint8_t*)peggy2_p->cols, PEGGY2_N_COL);
}