#include "Particle.h"
int ledPin = D1;
int switchPin = D3;
int photoCellPin = A0;
int photoCellReading = 0;
int ledBrightness = 0;
// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);
// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
SerialLogHandler logHandler(LOG_LEVEL_INFO);
// setup() runs once, when the device is first turned on
void setup() {
pinMode( switchPin , INPUT_PULLUP);
pinMode( ledPin , OUTPUT );
pinMode(ledPin, OUTPUT);
Particle.variable("light", &photoCellReading, INT);
// Put initialization like pinMode and begin functions here
}
void loop() {
photoCellReading = analogRead(photoCellPin);
ledBrightness = map(photoCellReading, 2700, 4095, 0, 255);
analogWrite(ledPin, ledBrightness);
delay(100);
int buttonState = digitalRead( switchPin );
if( buttonState == LOW );
{
// turn the LED On
digitalWrite(ledPin, HIGH);
}else{
digitalWrite(ledPin, LOW);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .