Created
May 30, 2020 18:54
-
-
Save pfiscarelli/7fab74979608ebf253888022e7b81480 to your computer and use it in GitHub Desktop.
TimberBOT - an Arduino sketch to play Timber Man on a TRS-80 Color Computer 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
TimberBOT | |
by: Paul Fiscarelli | |
Copyright (c) 2020, Paul Fiscarelli | |
MIT License | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. | |
*/ | |
#define RIGHT_LIMB_THRESHOLD 600 // threshold to detect limb on right-side of tree | |
#define LEFT_LIMB_THRESHOLD 300 // threshold to detect limb on left-side of tree | |
#define CHOP_MIN_THRESHOLD 155 // threshold for minimum chop rate (time in ms) | |
int eyesSensorPin = A0; // select the input pin for the potentiometer | |
int chopPin = A1; // select analog input for chop-rate potentiometer | |
int ledPin = 13; // select LED pin (output) | |
int xAxisPin = 2; // select xAxis pin (output) | |
int chopButtonPin = 3; // select chop ping (output) | |
int eyesSensorValue = 0; // input from eye sensors - differential voltage divider | |
int choppingRate = 0; // TimberBOT's chop rate | |
bool ledStatus = HIGH; // led pin output status | |
bool xAxisPosition = HIGH; // xAxis position | |
bool chopOutput = HIGH; // produce chop output | |
void setup() { | |
// designate pin functions: | |
pinMode(ledPin, OUTPUT); | |
pinMode(xAxisPin, OUTPUT); | |
pinMode(chopButtonPin, OUTPUT); | |
} | |
void loop() { | |
// read values from input sensors | |
eyesSensorValue = analogRead(eyesSensorPin); | |
choppingRate = (analogRead(chopPin) + CHOP_MIN_THRESHOLD) / 2; | |
Serial.println(choppingRate); | |
if (eyesSensorValue > RIGHT_LIMB_THRESHOLD){ | |
xAxisPosition = LOW; // tree limb on the right - move left | |
} | |
else if (eyesSensorValue < LEFT_LIMB_THRESHOLD){ | |
xAxisPosition = HIGH; // tree limb on the left - move right | |
} | |
else { | |
// keep current side of tree | |
} | |
// turn-on chop rate LED indicator | |
digitalWrite(ledPin, HIGH); | |
// move to correct side of tree and chop | |
digitalWrite(xAxisPin, xAxisPosition); | |
digitalWrite(chopButtonPin, LOW); | |
delay(choppingRate); | |
// turn-off chop rate LED indicator | |
digitalWrite(ledPin, LOW); | |
// release chop | |
digitalWrite(chopButtonPin, HIGH); | |
delay(choppingRate); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment