111 lines
2.5 KiB
C++
111 lines
2.5 KiB
C++
#include <Arduino.h>
|
|
|
|
/*
|
|
D7 - Ser (data)
|
|
D5 - clock
|
|
D1 - _OE
|
|
D2 - latch
|
|
D3 - _clear
|
|
*/
|
|
|
|
#define PIN_DATA D7
|
|
#define PIN_CLK D5
|
|
#define PIN_OE D1 //active low
|
|
#define PIN_LATCH D2
|
|
#define PIN_CLEAR D4 //active low
|
|
|
|
#define NUMPANELS 1
|
|
uint16_t dataRow = 0;
|
|
uint8_t dataControl = 0;
|
|
uint8_t dataColumn[NUMPANELS*7]; //raw data for shift register, 7bytes per panel (last 6 bits arent used)
|
|
|
|
void sr_clear();
|
|
void shiftOutSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
|
|
|
|
unsigned long loopmillis=0;
|
|
unsigned long last_update=0;
|
|
#define UPDATE_INTERVAL 1000
|
|
|
|
void setup() {
|
|
pinMode(PIN_DATA, OUTPUT);
|
|
pinMode(PIN_CLK, OUTPUT);
|
|
pinMode(PIN_OE, OUTPUT);
|
|
pinMode(PIN_LATCH, OUTPUT);
|
|
pinMode(PIN_CLEAR, OUTPUT);
|
|
|
|
digitalWrite(PIN_OE, HIGH);
|
|
digitalWrite(PIN_LATCH, LOW);
|
|
sr_clear();
|
|
|
|
Serial.begin(115200);
|
|
}
|
|
|
|
int countz=0;
|
|
|
|
void loop() {
|
|
loopmillis = millis();
|
|
if (loopmillis > last_update + UPDATE_INTERVAL)
|
|
{
|
|
|
|
dataControl=0;
|
|
#define CONTROL_LED 1
|
|
#define CONTROL_CLEAR 128 //active low
|
|
|
|
uint8_t selectedrow=0;
|
|
dataRow=2^selectedrow; //test select one row
|
|
|
|
|
|
if (countz%2==0) {
|
|
Serial.println("0");
|
|
}else{
|
|
dataControl=CONTROL_LED;
|
|
Serial.println("1");
|
|
|
|
}
|
|
|
|
//first shifted out bytes are farthest away in the line
|
|
|
|
shiftOutSlow(PIN_DATA, PIN_CLK, MSBFIRST, dataControl); //Control. Bit 1 is Qa
|
|
|
|
shiftOutSlow(PIN_DATA, PIN_CLK, MSBFIRST, dataControl); //Control. Bit 1 is Qa
|
|
shiftOutSlow(PIN_DATA, PIN_CLK, MSBFIRST, (uint8_t)(dataRow>>8)); //High Byte
|
|
shiftOutSlow(PIN_DATA, PIN_CLK, MSBFIRST, (uint8_t)dataRow); //Low Byte
|
|
|
|
digitalWrite(PIN_LATCH, HIGH); //Latch data
|
|
delayMicroseconds(1000);
|
|
digitalWrite(PIN_LATCH, LOW);
|
|
|
|
digitalWrite(PIN_OE, LOW); //activate output
|
|
last_update=loopmillis;
|
|
|
|
Serial.print("miau=");
|
|
Serial.println(countz);
|
|
countz++;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void sr_clear() {
|
|
digitalWrite(PIN_CLEAR, LOW);
|
|
delayMicroseconds(1000);
|
|
digitalWrite(PIN_CLEAR, HIGH);
|
|
}
|
|
|
|
void shiftOutSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
|
|
{
|
|
uint8_t i;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
if (bitOrder == LSBFIRST)
|
|
digitalWrite(dataPin, !!(val & (1 << i)));
|
|
else
|
|
digitalWrite(dataPin, !!(val & (1 << (7 - i))));
|
|
|
|
delayMicroseconds(100);
|
|
digitalWrite(clockPin, HIGH);
|
|
delayMicroseconds(100);
|
|
digitalWrite(clockPin, LOW);
|
|
delayMicroseconds(100);
|
|
}
|
|
} |