Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added photocell class

  • Loading branch information...
commit 6dcb55800c1c35697a544291b82e7ac7836ed26f 1 parent 946b335
@nyaculak nyaculak authored
View
21 LEDProject/LEDProject.ino
@@ -1,12 +1,14 @@
#include "rgbLED.h"
#include "Button.h"
#include "Thermistor.h"
+#include "PhotoCell.h"
#define redPin 13
#define greenPin 5
#define bluePin 3
#define buttonPin 2
-#define ThermistorPin A0
+#define thermistorPin A0
+#define photoPin A1
// create three LED instances
LED red(redPin);
@@ -20,7 +22,11 @@ rgbLED triled(&red, &green, &blue);
// create an instance of a digital button
Button button(buttonPin);
-Thermistor thermo(ThermistorPin);
+//create an instance of a Thermistor
+Thermistor thermo(thermistorPin);
+
+//create an instance of a PhotoCell
+PhotoCell photoCell(photoPin);
void setup() {
Serial.begin(9600); // begin serial communication at 9600 bps
@@ -28,7 +34,14 @@ void setup() {
}
void loop() {
- double temp = thermo.getTempFahrenheit();
- Serial.println(temp);
+ double val = photoCell.getValue();
+ Serial.println("Val:");
+ Serial.println(val);
+ if (val < 250) {
+ red.on();
+ }
+ else {
+ red.off();
+ }
}
View
11 LEDProject/PhotoCell.cpp
@@ -0,0 +1,11 @@
+#include <arduino.h>
+#include "PhotoCell.h"
+
+PhotoCell::PhotoCell(int _pinNumber) {
+ this->pinNumber = pinNumber;
+ pinMode(this->pinNumber, INPUT);
+}
+int PhotoCell::getValue() {
+ this->value = analogRead(this->pinNumber);
+ return this->value;
+}
View
10 LEDProject/PhotoCell.h
@@ -0,0 +1,10 @@
+#include <arduino.h>
+
+class PhotoCell {
+public:
+ PhotoCell(int _pinNumber);
+ int getValue();
+private:
+ int pinNumber;
+ int value;
+};
Please sign in to comment.
Something went wrong with that request. Please try again.