Created
May 8, 2016 03:36
-
-
Save vinirodr/c9c1ec1dd8076b1a6b988f0003bd435c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Include header file | |
#include "light.h" | |
Light::Light(int pin) { | |
Serial.begin(9600); | |
_pin = pin; | |
} | |
void Light::senseLight() { | |
lightLevel = analogRead(lightSensor); | |
Serial.println(lightLevel); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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