int State2 = 0;int Last2;int Pasos2;int PicosNum = 3;unsigned long previousMillis = 0; int RPS;int Ranking;int LastRanking;void setup() {Serial.begin(9600); // Use Serial Monitor windowpinMode(2, INPUT);}void loop(){ State2 = digitalRead(2); // Read the sensor //===== Eliminate Repeated counts if Last2 is = 1 ==================>>>>>>> if ((State2 == 1) & (Last2 == 0)) { Pasos2 = Pasos2 + 1; Last2 = 1; } else if (State2 == 0) { Last2 = 0; } //------------------------------------------------------------------------- //===== Read Numbers every 1 second ====================>>>>>>>>>>>>>>>>> unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= 1000) { previousMillis = currentMillis; RPS = (Pasos2 / PicosNum); Serial.print("Rev X Sec = "); Serial.print((RPS), DEC); Pasos2 = 0; if ((RPS >= 5) && (RPS <= 10)) //>> Add Numbers to Ranking every 1 second From 10 to 6 Revolutions per seconds { Ranking = Ranking + 1; LastRanking = Ranking; Serial.print(" / Ranking "); Serial.print((LastRanking), DEC); } else { Ranking = 0; } Serial.println(""); }}________________________________________________________________________________________________________________________________________________________________________________________________
int State2 = 0;int Last2;int Pasos2;int PicosNum = 3;unsigned long previousMillis = 0; int RPS;int Ranking;int LastRanking;int BotonCual;#include <LiquidCrystal.h>LiquidCrystal lcd(8, 9, 4, 5, 6, 7);void setup() { Serial.begin(9600); // Use Serial Monitor windowlcd.begin(16, 2); // start the librarypinMode(2, INPUT);pinMode(3, OUTPUT); digitalWrite(3, LOW); }void loop(){//================================================ Show Present >>>>>>>>>>>>if (digitalRead(3)==0) //Checa Presensia ON{ if (digitalRead(2)==1) //Checa Presensia ON { lcd.setCursor(14,0); lcd.print("X"); }}else{ if (digitalRead(2)==0) //Checa Presensia ON { lcd.setCursor(14,0); lcd.print("X"); } } //================================================ Select Picos >>>>>>>>>>>>BotonCual = analogRead(0); if ((BotonCual > 390) && (BotonCual< 450)){PicoCuantos();} if ((BotonCual > 80) && (BotonCual< 120)){PicoCuantosUP();} if ((BotonCual > 240) && (BotonCual< 280)){PicoCuantosDN();} if ((BotonCual > 630) && (BotonCual< 650)){PrendeElNegro();} //---------------------------------------------------------------------- State2 = digitalRead(2); // Read the sensor //===== Eliminate Repeated counts if Last2 is = 1 ==================>>>>>>> if ((State2 == 1) & (Last2 == 0)) { Pasos2 = Pasos2 + 1; Last2 = 1; } else if (State2 == 0) { Last2 = 0; } //------------------------------------------------------------------------- //===== Read Numbers every 1 second ====================>>>>>>>>>>>>>>>>> unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= 1000) { previousMillis = currentMillis; RPS = (Pasos2 / PicosNum); Serial.print("Rev X Sec = "); Serial.print((RPS), DEC); lcd.setCursor(0,0); lcd.print("Spin RPS "); lcd.setCursor(11,0); lcd.print((RPS), DEC); Pasos2 = 0; if ((RPS >= 5) && (RPS <= 10)) //>> Add Numbers to Ranking every 1 second From 10 to 6 Revolutions per seconds { Ranking = Ranking + 1; LastRanking = Ranking; Serial.print(" / Ranking "); Serial.print((LastRanking), DEC); lcd.setCursor(0,1); lcd.print("Ranking "); lcd.setCursor(12,1); lcd.print((LastRanking), DEC); } else { Ranking = 0; } Serial.println(""); }}void PicoCuantos(){lcd.clear();lcd.setCursor(0,0); lcd.print("Pik X Rev = "); lcd.setCursor(10,0); lcd.print(PicosNum);delay(1000);}void PicoCuantosUP(){lcd.clear();lcd.setCursor(0,0); lcd.print("Pik X Rev = "); lcd.setCursor(10,0); PicosNum = PicosNum + 1;if (PicosNum >=10){PicosNum=10;}lcd.print(PicosNum);delay(1000);}void PicoCuantosDN(){lcd.clear();lcd.setCursor(0,0); lcd.print("Pik X Rev = "); lcd.setCursor(10,0); PicosNum = PicosNum - 1;if (PicosNum <= 1){PicosNum=1;}lcd.print(PicosNum);delay(1000);}void PrendeElNegro(){if (digitalRead(3)==1) //Prende el Innnfrared para detectar Negro { digitalWrite(3, LOW); lcd.setCursor(15,0); lcd.print(" "); delay(1000); }else { digitalWrite(3, HIGH); lcd.setCursor(15,0); lcd.print("O"); delay(1000); }}