GY-63_MS5611/libraries/HT16K33/examples/demo3/demo3.ino

150 lines
2.3 KiB
Arduino
Raw Normal View History

2019-11-30 08:37:53 -05:00
//
// FILE: 4x7segmentI2C.ino
// AUTHOR: Rob Tillaart
2020-07-16 05:08:25 -04:00
// VERSION: 0.0.2
2019-11-30 08:37:53 -05:00
// PURPOSE: demo 3
// URL: http://www.adafruit.com/products/1002
2020-07-16 05:08:25 -04:00
// URL: https://github.com/RobTillaart/HT16K33
2019-11-30 08:37:53 -05:00
#include "HT16K33.h"
2020-07-16 05:08:25 -04:00
HT16K33 seg(0x70);
2019-11-30 08:37:53 -05:00
uint32_t start;
uint32_t stop;
uint8_t ar[4];
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
2020-07-16 05:08:25 -04:00
seg.begin();
2019-11-30 08:37:53 -05:00
Wire.setClock(100000);
seg.displayOn();
seg.suppressLeadingZeroPlaces(0);
Serial.println("displayTest()");
seg.displayTest(10);
seg.displayOff();
delay(1000);
seg.displayOn();
seg.displayColon(false);
}
void loop()
{
2020-07-16 05:08:25 -04:00
// comment tests you do not want to see
test_elsa();
delay(100);
test_random();
delay(100);
test_VULeft();
delay(100);
2019-11-30 08:37:53 -05:00
test_VURight();
2020-07-16 05:08:25 -04:00
delay(100);
test_VUStereo();
2019-11-30 08:37:53 -05:00
delay(100);
}
void test_elsa()
{
ar[0] = 0x79;
ar[1] = 0x38;
ar[2] = 0x6D;
ar[3] = 0x77;
seg.displayRaw(ar);
}
void test_random()
{
for (uint8_t i = 0; i < 4; i++)
{
ar[i] = random(256);
}
seg.displayRaw(ar);
}
void test_VULeft()
{
int val = analogRead(A0);
val = val / 120; // 0..8
seg.displayVULeft(val);
}
void test_VURight()
{
int val = analogRead(A0);
val = val / 120; // 0..8
seg.displayVURight(val);
}
void test_VUStereo()
{
uint8_t left = analogRead(A0) / 240; // 0..4
uint8_t right = analogRead(A1) / 240; // 0..4
displayVUStereo(left, right);
}
void displayVUStereo(uint8_t left, uint8_t right)
{
switch (left)
{
case 0:
ar[0] = 0x00;
ar[1] = 0x00;
break;
case 1:
ar[0] = 0x00;
ar[1] = 0x06;
break;
case 2:
ar[0] = 0x00;
ar[1] = 0x36;
break;
case 3:
ar[0] = 0x06;
ar[1] = 0x36;
break;
case 4:
default:
ar[0] = 0x36;
ar[1] = 0x36;
break;
}
switch (right)
{
case 0:
ar[2] = 0x00;
ar[3] = 0x00;
break;
case 1:
ar[2] = 0x30;
ar[3] = 0x00;
break;
case 2:
ar[2] = 0x36;
ar[3] = 0x00;
break;
case 3:
ar[2] = 0x36;
ar[3] = 0x30;
break;
case 4:
default:
ar[2] = 0x36;
ar[3] = 0x36;
break;
}
seg.displayRaw(ar);
2020-07-16 05:08:25 -04:00
2019-11-30 08:37:53 -05:00
// sort of heartbeat
static bool t = false;
seg.displayColon(t);
t = !t;
}
2020-07-16 05:08:25 -04:00
// -- END OF FILE --