Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Sensor Magnético
- int SM = 2;
- int LED = 13;
- int contador = 0;
- bool ativo = false;
- bool ultimo = false;
- void setup() {
- // put your setup code here, to run once:
- pinMode(SM, INPUT);
- pinMode(LED, OUTPUT);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- char c = Serial.read();
- if (c == 'Q') {
- ativo = true;
- ultimo = false;
- contador = 0;
- Serial.println();
- }
- if ( c == 'W' ) {
- ativo = false;
- ultimo = true;
- }
- if (ativo == true) {
- ativarSensor();
- }
- if (ultimo == true) {
- imprimeUltimo();
- }
- }
- void ativarSensor() {
- if (digitalRead(SM)) {
- contador = contador+1;
- digitalWrite(LED, HIGH);
- delay(100);
- digitalWrite(LED, LOW);
- delay(100);
- Serial.print(contador);
- }
- }
- void imprimeUltimo() {
- Serial.println(contador);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement