Back to Parent

//force resistor code based on tutorial https://docs.google.com/document/d/1KfkRd1UqBzrUTvw8Td6STyXqi8mmj_4G6rC4CB0OF_g/edit#heading=h.cwfvi2lnk1xg
//photoresistor code based on tutorial https://docs.google.com/document/d/1cpnWEScjDwxmhv_xTfwn8HPi3nZpJ2gO7ZOY5ChN1Q4/edit#heading=h.cwfvi2lnk1xg

int fsrPin = A0;
int photoPin = A2;
int grnPin = D2;
int redPin = D0;
int photoReading = 0;
int fsrReading = 0;
int ledBrightness1 = 0;
int ledBrightness2 = 0;

void setup()
{
pinMode(redPin, OUTPUT);
pinMode(grnPin, OUTPUT);
Spark.variable("light", &photoReading, INT);
Spark.variable("force", &fsrReading, INT);
}

void loop()
{
digitalWrite(redPin, LOW);
digitalWrite(grnPin, LOW);
photoReading = analogRead(photoPin);
fsrReading = analogRead(fsrPin);

ledBrightness1 = map(photoReading, 0, 4095, 0, 255);
ledBrightness2 = map(fsrReading, 0, 4095, 0, 255);

if(ledBrightness1 < 150 && ledBrightness2 >= 150){
analogWrite(redPin, ledBrightness1);
delay(250);
analogWrite(redPin, LOW);
delay(250);
analogWrite(redPin, ledBrightness1);
delay(250);
analogWrite(redPin, LOW);
delay(250);
analogWrite(redPin, ledBrightness1);
delay(250);
analogWrite(redPin, LOW);
delay(250);
}
else if(ledBrightness1 >= 150 || ledBrightness2 < 150){
digitalWrite(grnPin, ledBrightness1);
}
delay(100);

}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0