#define LDRpin A0 int LDRValue = 0; int LDRBefore = 0; int LDRCount = 0; // NEW int MotorRot = 0; // NEW int LedPin = 13; // NEW void setup() { Serial.begin(9600); pinMode(13, OUTPUT); digitalWrite(13, HIGH); // NEW } void loop() { LDRValue = analogRead(LDRpin); delay(1); /* Serial.print("LDRValue: "); // NEW Serial.println(LDRValue); Serial.print(" LDRBefore: "); Serial.print(LDRBefore); Serial.print(" LDRCount: "); Serial.print(LDRCount); Serial.print(" MotorRot: ");*/ Serial.println(MotorRot); if (LDRValue < LDRBefore) // NEW { LDRValue = LDRValue + 250; if (LDRValue <= LDRBefore) { LDRValue = LDRValue - 250; LDRCount = ++LDRCount; if (LDRCount == 20) { LDRCount = 0; MotorRot = ++MotorRot; } } else { LDRValue = LDRValue - 250; } } LDRBefore = LDRValue; }Attachments
code