Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@seth10
Last active September 8, 2017 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seth10/fd2b5a20854606148af93e107a7f8984 to your computer and use it in GitHub Desktop.
Save seth10/fd2b5a20854606148af93e107a7f8984 to your computer and use it in GitHub Desktop.
All complete programs from watch repo
//https://raw.githubusercontent.com/seth10/watch/31f9083a07451147009f5e92a93645e02fa69217/14seg/14seg.ino
#include "Adafruit_LEDBackpack.h"
char *message = " Hello world! ";
Adafruit_AlphaNum4 alpha4;
void setup() {
alpha4.begin();
for (uint8_t i=0; i<strlen(message)-4; i++) {
alpha4.writeDigitAscii(0, message[i]);
alpha4.writeDigitAscii(1, message[i+1]);
alpha4.writeDigitAscii(2, message[i+2]);
alpha4.writeDigitAscii(3, message[i+3], true); // true for period / digits-separator
alpha4.writeDisplay();
delay(200);
}
alpha4.clear();
alpha4.writeDisplay();
delay(1000);
}
void loop() {
for (uint8_t i=0; i<4; i++) {
alpha4.writeDigitRaw((i+4-1)%4, 0x0);
alpha4.writeDigitRaw(i, 0xFFFF);
alpha4.writeDisplay();
delay(200);
}
}
//https://raw.githubusercontent.com/seth10/watch/27d8a63f72db14d7b88bc18e221007f7a183e48e/button/button.ino
volatile int n = 0;
void isr() {
Serial.println(millis());
n++;
}
void setup() {
Serial.begin(9600);
pinMode(7, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(7), isr, FALLING);
}
void loop() {
Serial.println(n);
delay(200);
}
#define PIN_SDIN 1
#define PIN_SCLK 2
#include "font.h";
void oledWriteString(char *characters) {
while (*characters) oledWriteCharacter(*characters++);
}
void oledWriteCharacter(char character) {
for (int i=0; i<5; i++) oledWriteData(pgm_read_byte(&ASCII[character - 0x20][i]));
oledWriteData(0x00);
}
void oledWriteData(byte data) {
shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
}
void oledWriteCmd(byte command) {
shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, command);
}
void setup() {
pinMode(PIN_SDIN, OUTPUT);
pinMode(PIN_SCLK, OUTPUT);
oledWriteCmd(0x8d); //enable charge pump
oledWriteCmd(0x14);
delay(1);
oledWriteCmd(0xaf); //set display on
// oledWriteCmd(0xa8); //set MUX ratio
// oledWriteCmd(0x3f);
oledWriteCmd(0xd3); //set display offset
oledWriteCmd(0x00);
oledWriteCmd(0x40); //set display start line
oledWriteCmd(0xa1); //set segment re-map (horizontal flip) - reset value is 0xa0 (or 0xa1)
oledWriteCmd(0xc8); //set COM output scan direction (vertical flip) - reset value is 0xc0 (or 0xc8)
oledWriteCmd(0xda); //set COM pins hardware configuration
oledWriteCmd(0x12); //reset value is 0x12
oledWriteCmd(0x81); //set contrast (2-byte)
oledWriteCmd(0xff);
// oledWriteCmd(0xa4); //disable entire display on
// oledWriteCmd(0xa6); //set normal display
// oledWriteCmd(0xd5); //set oscillator frequency
// oledWriteCmd(0x80);
// oledWriteCmd(0xdb); //vcomh deselect level (brightness)
// oledWriteCmd(0x20);
oledWriteCmd(0x20); //set horizontal addressing mode for screen clear
oledWriteCmd(0x01);
oledWriteCmd(0x21); //set column start and end address
oledWriteCmd(0x00); //set column start address
oledWriteCmd(0x7f); //set column end address
oledWriteCmd(0x22); //set row start and end address
oledWriteCmd(0x00); //set row start address
oledWriteCmd(0x07); //set row end address
for (int i=0; i<1024; i++) oledWriteData(0x01); // clear oled screen
oledWriteCmd(0x20); //set page addressing mode
oledWriteCmd(0x02);
oledWriteCmd(0xb7); //set page start address to page 7
oledWriteCmd(0x00); //set lower column start address
oledWriteCmd(0x10); //set upper column start address
oledWriteString("Julian's Code");
// oledWriteCmd(0x27); //set right horizontal scroll
// oledWriteCmd(0x0); //dummy byte
// oledWriteCmd(0x0); //page start address
// oledWriteCmd(0x7); //scroll speed
// oledWriteCmd(0x7); //page end address
// oledWriteCmd(0x0); //dummy byte
// oledWriteCmd(0xff); //dummy byte
// oledWriteCmd(0x2f); //start scrolling
oledWriteCmd(0xb0); //set page start address to page 0
}
char tmp[8];
void loop() {
static unsigned long thisMicros = 0;
static unsigned long lastMicros = 0;
oledWriteCmd(0x00); //set lower column start address
oledWriteCmd(0x10); //set upper column start address
oledWriteString(dtostrf(thisMicros - lastMicros,8,0,tmp));
lastMicros = thisMicros;
thisMicros = micros();
// oledWriteString(" microseconds");
}
#define PIN_CS 8
#define PIN_DC 9
#define PIN_RESET 10
#define PIN_SDIN 11
#define PIN_SCLK 12
#include "font.h";
char tmp[8];
void oledWriteString(char *characters)
{
while (*characters) oledWriteCharacter(*characters++);
}
void oledWriteCharacter(char character)
{
for (int i=0; i<5; i++) oledWriteData(pgm_read_byte(&ASCII[character - 0x20][i]));
oledWriteData(0x00);
}
void oledWriteData(byte data)
{
digitalWrite(PIN_DC, HIGH);
digitalWrite(PIN_CS, LOW);
shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
digitalWrite(PIN_CS, HIGH);
}
void oledWriteCmd(byte command)
{
digitalWrite(PIN_DC, LOW);
digitalWrite(PIN_CS, LOW);
shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, command);
digitalWrite(PIN_CS, HIGH);
}
void setup()
{
pinMode(PIN_RESET, OUTPUT);
pinMode(PIN_CS, OUTPUT);
pinMode(PIN_DC, OUTPUT);
pinMode(PIN_SDIN, OUTPUT);
pinMode(PIN_SCLK, OUTPUT);
// digitalWrite(PIN_RESET, HIGH);
digitalWrite(PIN_RESET, LOW);
delay(1);
digitalWrite(PIN_RESET, HIGH);
delay(1);
oledWriteCmd(0x8d); //enable charge pump
oledWriteCmd(0x14);
delay(1);
oledWriteCmd(0xaf); //set display on
// oledWriteCmd(0xa8); //set MUX ratio
// oledWriteCmd(0x3f);
oledWriteCmd(0xd3); //set display offset
oledWriteCmd(0x00);
oledWriteCmd(0x40); //set display start line
oledWriteCmd(0xa1); //set segment re-map (horizontal flip) - reset value is 0xa0 (or 0xa1)
oledWriteCmd(0xc8); //set COM output scan direction (vertical flip) - reset value is 0xc0 (or 0xc8)
oledWriteCmd(0xda); //set COM pins hardware configuration
oledWriteCmd(0x12); //reset value is 0x12
oledWriteCmd(0x81); //set contrast (2-byte)
oledWriteCmd(0xff);
// oledWriteCmd(0xa4); //disable entire display on
// oledWriteCmd(0xa6); //set normal display
// oledWriteCmd(0xd5); //set oscillator frequency
// oledWriteCmd(0x80);
// oledWriteCmd(0xdb); //vcomh deselect level (brightness)
// oledWriteCmd(0x20);
oledWriteCmd(0x20); //set horizontal addressing mode for screen clear
oledWriteCmd(0x01);
oledWriteCmd(0x21); //set column start and end address
oledWriteCmd(0x00); //set column start address
oledWriteCmd(0x7f); //set column end address
oledWriteCmd(0x22); //set row start and end address
oledWriteCmd(0x00); //set row start address
oledWriteCmd(0x07); //set row end address
for (int i=0; i<1024; i++) oledWriteData(0x00); // clear oled screen
oledWriteCmd(0x20); //set page addressing mode
oledWriteCmd(0x02);
oledWriteCmd(0xb7); //set page start address to page 7
oledWriteCmd(0x00); //set lower column start address
oledWriteCmd(0x10); //set upper column start address
oledWriteString("Julian's Code");
// oledWriteCmd(0x27); //set right horizontal scroll
// oledWriteCmd(0x0); //dummy byte
// oledWriteCmd(0x0); //page start address
// oledWriteCmd(0x7); //scroll speed
// oledWriteCmd(0x7); //page end address
// oledWriteCmd(0x0); //dummy byte
// oledWriteCmd(0xff); //dummy byte
// oledWriteCmd(0x2f); //start scrolling
oledWriteCmd(0xb0); //set page start address to page 0
}
void loop()
{
static unsigned long thisMicros = 0;
static unsigned long lastMicros = 0;
oledWriteCmd(0x00); //set lower column start address
oledWriteCmd(0x10); //set upper column start address
oledWriteString(dtostrf(thisMicros - lastMicros,8,0,tmp));
lastMicros = thisMicros;
thisMicros = micros();
// oledWriteString(" microseconds");
}
//https://raw.githubusercontent.com/seth10/watch/881a2d2bf47059b764ad8b4564ea1699b423932f/button/button.ino
//https://raw.githubusercontent.com/seth10/watch/4f70d0e553802a5321edefba65078cbfd75a3e42/button/button.ino
volatile byte minutes = 0, hours = 0;
volatile unsigned long lastISR = 0;
volatile unsigned long delta;
volatile byte sequence = 0;
void isr() {
delta = millis() - lastISR;
lastISR = millis();
if (delta < 100) return; // debounce
/**/ if (delta > 5000) sequence = 0;
else if (delta > 4000) sequence = 4;
else if (delta > 3000) sequence = 3;
else if (delta > 2000) sequence = 2;
else if (delta > 1000) sequence = 1;
switch (sequence) {
case 1: minutes = (minutes+1) % 60; break;
case 2: minutes = (minutes+10) % 60; break;
case 3: hours = (hours+1) % 24; break;
case 4: hours = (hours+6) % 24; break;
}
}
void setup() {
Serial.begin(9600);
pinMode(7, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(7), isr, FALLING);
}
void loop() {
Serial.print('\r');
if (hours < 10) Serial.print('0');
Serial.print(hours);
Serial.print(':');
if (minutes < 10) Serial.print('0');
Serial.print(minutes);
delay(50);
}
//https://raw.githubusercontent.com/seth10/watch/efb2b8b4592eacf08dc2c9a9478a835e587d59b3/button/button.ino
void setup() {
pinMode(4, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
if (digitalRead(4))
digitalWrite(LED_BUILTIN, LOW);
else
digitalWrite(LED_BUILTIN, HIGH);
}
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// If using software SPI (the default case):
#define OLED_MOSI 11 //D1
#define OLED_CLK 12 //D0
#define OLED_DC 9
#define OLED_CS 8
#define OLED_RESET 10
Adafruit_SSD1306 display;
void setup() {
// Serial.begin(9600);
display.begin();
display.display();
delay(1000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
}
void loop()
{
static unsigned long thisMicros = 0;
static unsigned long lastMicros = 0;
display.clearDisplay();
display.setCursor(0,0);
display.print("Now is the time for all good men to come to the aid the party \n");
display.print("The quick brown fox jumps over a lazy dog \n");
display.print(thisMicros - lastMicros);
display.print(" microseconds");
display.display();
lastMicros = thisMicros;
thisMicros = micros();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment