#include int latchPin = 5; // Latch pin of 74HC595 is connected to Digital pin 5 int clockPin = 6; // Clock pin of 74HC595 is connected to Digital pin 6 int dataPin = 4; // Data pin of 74HC595 is connected to Digital pin 4 byte leds = 0; // Variable to hold the pattern of which LEDs are currently turned on or off void setup() { // Set all the pins of 74HC595 as OUTPUT pinMode(latchPin, OUTPUT); pinMode(dataPin, OUTPUT); pinMode(clockPin, OUTPUT); Serial.begin(9600); while (!Serial) ; if (!APDS.begin()) { Serial.println("Error initializing APDS-9960 sensor."); } Serial.println("READY!"); } void loop() { if (APDS.gestureAvailable()) { // A gesture was detected, read and print to Serial Monitor. int gesture = APDS.readGesture(); switch (gesture) { case GESTURE_UP: Serial.println("Detected UP gesture"); break; case GESTURE_DOWN: Serial.println("Detected DOWN gesture"); break; case GESTURE_LEFT: Serial.println("Detected LEFT gesture"); for (int i = 7; i >= 0; i--) // Turn all the LEDs ON one by one. { bitSet(leds, i); // Set the bit that controls that LED in the variable 'leds' updateShiftRegister(); delay(100); } delay(1000); break; case GESTURE_RIGHT: Serial.println("Detected RIGHT gesture"); for (int i = 0; i < 8; i++) // Turn all the LEDs ON one by one. { bitSet(leds, i); // Set the bit that controls that LED in the variable 'leds' updateShiftRegister(); delay(100); } delay(1000); break; default: // Ignore. break; } } // end if gesture available leds = 0; // Initially turns all the LEDs off, by giving the variable 'leds' the value 0 updateShiftRegister(); // delay(1000); } void updateShiftRegister() { digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, LSBFIRST, leds); digitalWrite(latchPin, HIGH); }