is this right?
int sensor = 1;
unsigned long startMillis; //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 1000; //the value is a number of milliseconds
const byte ledPin = 13; //using the built in LED
int lowstate = 0;
int hightstate = 0;
long ratio = 0;
void setup() {
Serial.begin(9600);
pinMode(sensor, INPUT);
startMillis = millis(); //initial start time
}
void loop() {
currentMillis = millis();
int state = digitalRead(sensor);
if(state == 1) hightstate = hightstate +1;
if(state == 0) lowstate = lowstate +1;
ratio = hightstate / (lowstate+hightstate);
if (currentMillis - startMillis >= period) //test whether the period has elapsed
{
Serial.println(state);
startMillis = currentMillis; //IMPORTANT to save the start time of the current LED state.
}
}