Skip to content

Instantly share code, notes, and snippets.

@vinirodr
Created May 8, 2016 03:36
Show Gist options
  • Save vinirodr/c9c1ec1dd8076b1a6b988f0003bd435c to your computer and use it in GitHub Desktop.
Save vinirodr/c9c1ec1dd8076b1a6b988f0003bd435c to your computer and use it in GitHub Desktop.
// Include Light Sensor library
#include "light.h"
int sensorPin;
void setup() {
// Set sensor pin
sensorPin = 0;
}
void loop() {
// Create instance of sensor lib
Light mySensor(sensorPin);
// Run, start sensing method
mySensor.senseLight();
}
// Include header file
#include "light.h"
Light::Light(int pin) {
Serial.begin(9600);
_pin = pin;
}
void Light::senseLight() {
lightLevel = analogRead(lightSensor);
Serial.println(lightLevel);
}
#ifndef Light_h
#define Light_h
class Light {
public:
Light(int level);
void senseLight();
private:
int _lightLevel;
int _pin;
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment