#include #define RX 1 // SCK i reversed them to read and debug #define TX 2 // MISO SoftwareSerial Serial(RX, TX); const int PTPin = 3; // pin that the sensor is attached to const int laser = 4; // pin that the LED is attached to int capCount = 0; //total count of cap, init zero bool currentState = 1; // to store new state after cap pass int countTrigger = 25; //value the PT exceeds to count cap int resetTrigger = 10; //value at which to start counting again int val=0; void setup() { pinMode(PTPin, INPUT); pinMode(laser, OUTPUT); digitalWrite(laser, HIGH); Serial.begin(9600); Serial.println("HELLO"); } void loop() { // if (Serial.available()) { // char MasterCommand = Serial.read(); // if(MasterCommand == 'O') { // Serial.println('R'); // checkInput(); //reads the PT and counts // } // } //val = analogRead(PTPin); //Serial.println(val); checkInput(); //reads the PT and counts } void checkInput() { int PTValue = 0; for(int i = 0; i<5; i++){ // for accuracy taking 5 readings and averaging PTValue += analogRead(PTPin); } PTValue= PTValue / 5; //Serial.println(PTValue); if (currentState == 1) //actively looking for cap { if (PTValue >= countTrigger){ //if PT goes above trigger cap is detected currentState = 0; //stop listening for new counts until it gets bright again capCount++; //increment the count Serial.println(capCount); } } else //currentstate was false, don't check for cap, check for reset { if (PTValue <= resetTrigger){ //if value was below the reset threshhold currentState = 1; //start listening again } } if (capCount == 5){ capCount = 0; Serial.println('F'); } checkInput(); }