Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define LATCH_BIT 0 //white
- #define CLOCK_BIT 1 //yellow
- #define DATA_BIT 2
- #define LATCH_PIN A0
- #define CLOCK_PIN A1
- #define DATA_PIN A2
- #define FIXED_TIME 0
- void initPins();
- void sendButtons();
- void setup()
- {
- initPins();
- disableTimers();
- noInterrupts();
- }
- #define readLatch() ((PINC & (1 << LATCH_BIT)) ? HIGH : LOW )
- #define readClock() ((PINC & (1 << CLOCK_BIT)) ? HIGH : LOW )
- #define sendButtonState(btns) PORTC = (PORTC & (~(1<<DATA_BIT))) | ((btns & 1) << DATA_BIT); btns = (btns >> 1)
- #define waitForClockCycle() while(readClock() == HIGH);while(readClock() == LOW)
- void loop()
- {
- if(readLatch() != HIGH) {
- return;
- }
- unsigned int pind = B11111100;
- unsigned int pinb = B00111011;
- //unsigned int left = B00000010;
- //unsigned int right = B00000001;
- unsigned int buttonsLow = pind >> 2;
- unsigned int buttonsHigh = pinb & B00111111;
- while( readLatch() == HIGH);
- sendButtonState(buttonsLow);
- waitForClockCycle();
- sendButtonState(buttonsLow);
- waitForClockCycle();
- sendButtonState(buttonsLow);
- waitForClockCycle();
- sendButtonState(buttonsLow);
- waitForClockCycle();
- sendButtonState(buttonsLow);
- waitForClockCycle();
- sendButtonState(buttonsLow);
- waitForClockCycle();
- sendButtonState(buttonsHigh);
- waitForClockCycle();
- sendButtonState(buttonsHigh);
- waitForClockCycle();
- sendButtonState(buttonsHigh);
- waitForClockCycle();
- sendButtonState(buttonsHigh);
- waitForClockCycle();
- sendButtonState(buttonsHigh);
- waitForClockCycle();
- sendButtonState(buttonsHigh);
- waitForClockCycle();
- PORTC |= (1<<DATA_BIT);
- }
- void initPins() {
- pinMode(LATCH_PIN, INPUT);
- pinMode(CLOCK_PIN, INPUT);
- pinMode(DATA_PIN, OUTPUT);
- digitalWrite(DATA_PIN, LOW);
- }
- void disableTimers() {
- TCCR0A = 0;
- TCCR0B = 0;
- TCCR1A = 0;
- TCCR1B = 0;
- TCCR2A = 0;
- TCCR2B = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement