/* * one pot fades one motor * modified version of AnalogInput * by DojoDave * http://www.arduino.cc/en/Tutorial/AnalogInput * Modified again by dave */ int potPin = 0; // select the input pin for the potentiometer int motorPin = 9; // select the pin for the Motor int val = 0; // variable to store the value coming from the sensor char serialInArray[100]; int minuteDelay; boolean alarmSet = false; void setup() { Serial.begin(9600); } void loop() { readSerialString(serialInArray, 100); processSet(); delay(minuteDelay * 2 * 1000); //val = analogRead(potPin); // read the value from the sensor, between 0 - 1024 //Serial.println(val); if(alarmSet == true) { Serial.println("Buzzing alarm"); for(int i=50; i< 255; i+=50) { analogWrite(motorPin, i); // analogWrite can be between 0-255 delay(5000); readSerialString(serialInArray, 100); processOff(); } analogWrite(motorPin, 0); alarmSet = false; } } void processSet() { int valueRead; valueRead = serialInArray[0]; if(valueRead == 0) { analogWrite(motorPin, 0); } else { minuteDelay = atoi(serialInArray); Serial.print("An alarm is set to buzz you in "); Serial.print(minuteDelay); Serial.println("minutes"); alarmSet = true; } } void processOff() { int valueRead; valueRead = serialInArray[0]; if(valueRead == ' ' || valueRead == 0) { analogWrite(motorPin, 0); } } void readSerialString (char *strArray, int maxLength) { int i = 0; if(!Serial.available()) { return; } while (Serial.available() && i < maxLength) { strArray[i] = Serial.read(); i++; } } void resetSerialString (char *strArray, int length) { for (int i = 0; i < length; i++) { strArray[i] = '\0'; } }