Paso 6: El código
int sensorPin = A0; int potensioPin = A1; int ledPin = 13; int sensorValue = 0; int potensioValue = 0; int laserPin = 12; void setup() { //Serial.begin(9600); pinMode(ledPin, OUTPUT); pinMode(2, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(8, OUTPUT); pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(laserPin, OUTPUT); } void loop() { digitalWrite(laserPin, HIGH); sensorValue = analogRead(sensorPin); potensioValue = analogRead(potensioPin); sensorValue = map(sensorValue, 0, 1023, 0, 100); potensioValue = map(potensioValue, 0, 1023, 0, 100); //Serial.println(potensioValue); if(sensorValue < 99){ digitalWrite(5, HIGH); digitalWrite(6, HIGH); digitalWrite(7, HIGH); digitalWrite(8, HIGH); digitalWrite(9, HIGH); digitalWrite(10, HIGH); digitalWrite(11, HIGH); for(int i=0; i <= potensioValue; i++){ digitalWrite(ledPin, HIGH); delay(100); digitalWrite(ledPin, LOW); delay(100); buzz(7, 2500, 200); buzz(9, 2500, 200); if(i == potensioValue) { buzz(2, 2500, 100 * potensioValue); buzz(9, 2500, 100 * potensioValue); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(10, LOW); digitalWrite(11, LOW); } } } } void buzz(int targetPin, long frequency, long length) { long delayValue = 1000000/frequency/2; long numCycles = frequency * length/ 1000; for (long i=0; i < numCycles; i++){ digitalWrite(targetPin,HIGH); delayMicroseconds(delayValue); digitalWrite(targetPin,LOW); delayMicroseconds(delayValue); } }
Gracias a leer este instructables y espero que este útil...