Skip to content

7. Input & Output device

Inputs consist of signals or data received by the system, while outputs are signals or data transmitted from it. Input devices encompass keyboards, mice, microphones, webcams, and scanners. Output devices enable users to perceive the results of computer processing through sight, sound, or other means. Typical output devices include monitors, printers, speakers, and headphones.

This week, I have chosen to utilize a gesture sensor to develop code for my final project. The project involves a sensor that detects motion and uses it to control the activation of a light, along with making adjustments to the light’s color settings.

Code Used

#include "Adafruit_APDS9960.h"
Adafruit_APDS9960 apds;
#include <SPI.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN        5
#define NUMPIXELS 10
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500 

void setup() {
  #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif
  pixels.begin(); 
  Serial.begin(115200);

  if(!apds.begin()){
    Serial.println("failed to initialize device! Please check your wiring.");
  }
  else Serial.println("Device initialized!");

  apds.enableProximity(true);
  apds.enableGesture(true);
}

void loop() {
  pixels.clear();
  uint8_t gesture = apds.readGesture();

  if(gesture == APDS9960_DOWN) {

    Serial.println("ON");

    for(int i=0; i<NUMPIXELS; i++) {
      pixels.setPixelColor(i, pixels.Color(255, 255, 255));
      pixels.show();
      delay(DELAYVAL);
      }

    }

  else if(gesture == APDS9960_UP) {
  Serial.println("OFF");
  for(int i=0; i<NUMPIXELS; i++)
    {
      pixels.setPixelColor(i, pixels.Color(0, 0, 0));
      pixels.show();
      delay(DELAYVAL);}}

}


Last update: July 18, 2024