// SETA43 const int buttonPin = 2; const int ledPin = 13; const int SoundPin = 12; int buttonState ; void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); pinMode(SoundPin, OUTPUT); pinMode(buttonPin, INPUT); } void loop() { int z; buttonState = digitalRead(buttonPin); delay(300); if (buttonState == HIGH) { Serial.println("Sensor activado"); digitalWrite(ledPin, HIGH); for(z=0;z<150;z++) { digitalWrite(SoundPin, HIGH); delay(1); digitalWrite(SoundPin, LOW); delay(1); } } else { Serial.println("Sensor parado"); digitalWrite(ledPin, LOW); } } |