/* * LeslieAuto1.ino * Automatic and Manual Control for A Two-Motor Leslie 31H Tallboy speaker * * Arduino Diecimila/Atmega168 sketch * Author: G. Forrest Cook * License: GPL Version 3. * April 20, 2024 * * The Stop switch turn both motors off. * The Run switch turn both motors off while the switch is pressed, then off. * In Auto mode, the motors turn on and off at a rate that always keeps * the two rotors spinning up and down, the change in speed gives the * most interesting sound. Note that the two rotors are intentionally * out of sync with each other. * * If the Run switch is pressed while Auto mode is on, both motors * turn on while the switch is pressed, then return to Auto mode when the * switch is released. * This gives the player the ability to manually spin up both rotors * before returning to Auto mode. * * Auto mode will timeout after 300 seconds to prevent wear on the * mechanism if the player walks away, pressing the Run switch while in * Auto mode will reset the timeout counter before resuming Auto mode. * * Uncomment the Serial lines for debugging purposes. */ const int WoofPin = 8; // Woofer SSR Motor, active low const int TweetPin = 9; // Tweeter SSR Motor, active low const int LedPin = 13; // Arduino built-in LED, active high const int StopPin = 5; // Switch for motor stop act Low (PD5) const int AutoPin = 6; // Switch for motor auto act Low (PD6) const int RunPin = 7; // Switch for motor run control act Low (PD7) int WoofCount = 0; // 3.5 seconds off, 4 seconds on int WoofOn = 35; int WoofMax = 75; int TweetCount = 0; // .5 seconds off, .7 seconds off int TweetOn = 5; int TweetMax = 12; int LoopDelay = 100; // 100ms time steps int AutoMode = 0; // 0 for Stop and Run, 1 for Auto int AutoMax = 3000; // shutdown Auto mode after N/10 Sec. int AutoCount = 0; void setup() { pinMode (2, OUTPUT); // set unused pins to output mode pinMode (3, OUTPUT); pinMode (4, OUTPUT); pinMode (LedPin, OUTPUT); pinMode (StopPin, INPUT); pinMode (AutoPin, INPUT); pinMode (WoofPin, OUTPUT); pinMode (TweetPin, OUTPUT); pinMode (10, OUTPUT); pinMode (11, OUTPUT); pinMode (12, OUTPUT); pinMode (RunPin, INPUT); digitalWrite(WoofPin, HIGH); digitalWrite(TweetPin, HIGH); // Serial.begin (19200); // Initialize serial port, set the baud rate AutoMode = 0; BlinkYel (3); // blink the on-board yellow LED at startup Serial.println (F("Leslie Controller V1")); } void loop() { // Serial.print (F("WoofCount: ")); // Serial.print (WoofCount); // Serial.print (F("\tTweetCount: ")); // Serial.println (TweetCount); /* Loop waiting for a switch closure */ if (!digitalRead (AutoPin)) // Check for auto mode switch { if (AutoMode != 1) // auto mode not already on { digitalWrite(WoofPin, HIGH); // motors Off digitalWrite(TweetPin, HIGH); AutoMode = 1; } AutoCount = 0; // reset the timeout // Serial.println (F("Auto Switch")); while (!digitalRead (AutoPin)); } else if (!digitalRead (StopPin)) // Check for stop switch { digitalWrite(WoofPin, HIGH); // motors Off digitalWrite(TweetPin, HIGH); WoofCount=0; TweetCount=0; AutoMode = 0; // reset the timeout // Serial.println (F("Stop Switch")); while (!digitalRead (StopPin)); } else if (!digitalRead (RunPin)) // Check for run switch { digitalWrite(WoofPin, LOW); // motors On digitalWrite(TweetPin, LOW); WoofCount=0; TweetCount=0; // Serial.println (F("Run Switch")); while (!digitalRead (RunPin)); digitalWrite(WoofPin, HIGH); // motors Off digitalWrite(TweetPin, HIGH); if (AutoMode == 1) // Go back to Auto mode AutoCount = 0; // and restart the timeout else AutoMode = 0; } if (AutoMode == 1) // Deal with Auto mode { WoofCount++; if (WoofCount == WoofOn) { digitalWrite(WoofPin, LOW); // Serial.println (F("Woofer Motor On")); } if (WoofCount > WoofMax) { WoofCount = 0; digitalWrite(WoofPin, HIGH); // Serial.println (F("Woofer Motor Off")); } TweetCount++; if (TweetCount == TweetOn) { digitalWrite(TweetPin, LOW); // Serial.println (F("Tweeter Motor On")); } if (TweetCount > TweetMax) { TweetCount = 0; digitalWrite(TweetPin, HIGH); // Serial.println (F("Tweeter Motor Off")); } // Serial.println (AutoCount); AutoCount++; if (AutoCount > AutoMax) // check for timeout { digitalWrite(WoofPin, HIGH); digitalWrite(TweetPin, HIGH); WoofCount=0; TweetCount=0; AutoMode = 0; // Serial.println (F("Auto Mode Timeout")); } } delay(LoopDelay); } void BlinkYel(byte count) // blink yellow LED on Digi-13 (PB5) { byte i; for (i=0; i