Last active
August 29, 2015 14:03
-
-
Save lennerd/2f8cf67e9df85464c4cf to your computer and use it in GitHub Desktop.
Clean way to received signals from the RCC-controller on the Arduino
This file contains hidden or 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
/* | |
MIT License | |
Copyright (c) 2014 Lennart Hildebrandt aka lennerd (https://github.com/lennerd) | |
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. | |
See also: http://www.opensource.org/licenses/mit-license.php | |
*/ | |
const int rccRightPin = A2; | |
const int rccLeftPin = A3; | |
const int rccForwardPin = A0; | |
const int rccBackwardPin = A1; | |
boolean rccRightStatus = false; | |
boolean rccLeftStatus = false; | |
boolean rccForwardStatus = false; | |
boolean rccBackwardStatus = false; | |
void setup() {/* | |
//Serial.begin(9600); | |
pinMode(rccRightPin, INPUT); | |
pinMode(rccLeftPin, INPUT); | |
pinMode(rccForwardPin, INPUT); | |
pinMode(rccBackwardPin, INPUT); | |
analogReference(EXTERNAL); | |
} | |
void loop() { | |
//Serial.println(digitalRead(rccRightPin)); | |
//Serial.println(digitalRead(rccLeftPin)); | |
//Serial.println(analogRead(rccForwardPin)); | |
//Serial.println(analogRead(rccBackwardPin)); | |
/* | |
* The following variables are holding true or false, | |
* so we can use them later on in some if(...) { ... } statements | |
*/ | |
rccRightStatus = digitalRead(rccRightPin) == LOW; // LOW means ACTIVE, turn right | |
rccLeftStatus = digitalRead(rccLeftPin) == LOW; // LOW means ACTIVE, turn left | |
rccForwardStatus = analogRead(rccForwardPin) < 50; // Analog input value under 50 means ACTIVE, drive forward | |
rccBackwardStatus = analogRead(rccBackwardPin) < 50; // Analog input value under 50 means ACTIVE, drive backward | |
/* | |
* Now you can use these variables to control your outputs ... for example: | |
*/ | |
if (rccForwardStatus || rccBackwardStatus) { | |
// RCC motor is running forward or backward | |
} | |
if (rccRightStatus || rccLeftStatus) { | |
// RCC magnets are turning the car right or left | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For this Hack we used the Amewi 22046 - Mini Racing Buggy Pegasus M:
http://www.amazon.de/dp/B002NF5FZ0