Created
November 8, 2024 22:55
-
-
Save todbot/6e63f155780403ce2e52770803323240 to your computer and use it in GitHub Desktop.
simple AS1115 LED driver demo, for the Supercon "petal" SAO, in Arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// as1115_test.ino -- simple AS1115 LED driver demo, for the Supercon "petal" SAO | |
// 1 Nov 2024 - @todbot / Tod Kurt | |
// written for arduino-pico Arduino core, but should be usable for others | |
#include <Wire.h> | |
// simple class for dealing with AS1115 LED driver chip: | |
// https://ams-osram.com/products/drivers/led-drivers/ams-as1115-led-driver-ic | |
class AS1115_test { | |
public: | |
AS1115_test() {} | |
void begin(TwoWire *aWire = &Wire, uint8_t an_i2c_addr = 0) { | |
theWire = aWire; | |
i2c_addr = an_i2c_addr; | |
// set up the chip with the settings we want | |
writeReg(0x09, 0x00); // raw pixel mode, not 7-seg mode | |
writeReg(0x0A, 0x01); // set intensity 0-15 | |
writeReg(0x0B, 0x07); // enable all segments | |
writeReg(0x0C, 0x81); // undo shutdown | |
writeReg(0x0D, 0x00); // self-addressing | |
writeReg(0x0E, 0x00); // no crazy features (default?) | |
writeReg(0x0F, 0x00); // turn off display test | |
} | |
// write to a particular register of the chip with a given value | |
void writeReg(uint8_t reg, uint8_t regval) { | |
theWire->beginTransmission(i2c_addr); | |
theWire->write(reg); | |
theWire->write(regval); | |
theWire->endTransmission(); | |
} | |
//// convenience functions //// | |
void setIntensity(uint8_t v) { | |
writeReg(0x0A, v); // set intensity 0-15 | |
} | |
// turn all segements off | |
void off() { | |
for( int x=0; x<8; x++) { | |
writeReg(x+1, 0); | |
} | |
} | |
uint8_t i2c_addr; | |
TwoWire *theWire; | |
}; | |
AS1115_test as1115 = AS1115_test(); | |
void setup() | |
{ | |
Serial.begin(115200); | |
Wire.setSCL(17); // SAO connector on pins 16,17 (which are on i2c0 aka 'Wire') | |
Wire.setSDA(16); | |
Wire.begin(); // join i2c bus | |
as1115.begin( &Wire ); | |
as1115.off(); | |
} | |
uint8_t digitnum = 1; | |
void loop() | |
{ | |
Serial.printf("hello world! digit:%d\n", digitnum); | |
//as1115.off(); | |
as1115.writeReg(digitnum, 0x00); // turn off previous digit ('arm' on petal SAO) | |
digitnum++; | |
if( digitnum == 9) { digitnum = 1; } | |
as1115.writeReg(digitnum, 0x7F); // write new digit (or 'arm' on petal SAO) | |
delay(100); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment