Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define CUSTOM_SETTINGS
- #define INCLUDE_GAMEPAD_SHIELD
- /* Include 1Sheeld library. */
- #include <OneSheeld.h>
- #include <Servo.h>
- #include <Wire.h>
- Servo SteeringServo;
- int MaxSteerAngle = 30;
- int Speed = 0;
- int MaxSpeed = 100;
- int RPWM_Output = 5; // Arduino PWM output pin 5; connect to IBT-2 pin 1 (RPWM)
- int LPWM_Output = 6; // Arduino PWM output pin 6; connect to IBT-2 pin 2 (LPWM)
- void setup() {
- Serial.begin(115200);
- OneSheeld.begin();
- pinMode(RPWM_Output, OUTPUT);
- pinMode(LPWM_Output, OUTPUT);
- SteeringServo.attach(7);
- }
- void loop() {
- if (GamePad.isUpPressed()) { // Forwards
- analogWrite(LPWM_Output, 0);
- analogWrite(RPWM_Output, Speed);
- }
- if (GamePad.isDownPressed()) {
- analogWrite(LPWM_Output, Speed); // Backwards
- analogWrite(RPWM_Output, 0);
- }
- if (GamePad.isRightPressed()) { // Steer Left
- SteeringServo.write(90 + MaxSteerAngle);
- }
- if (GamePad.isLeftPressed()) { // Steer Right
- SteeringServo.write(90 - MaxSteerAngle);
- }
- if (GamePad.isRedPressed()) { // Stop all Engines
- analogWrite(LPWM_Output, 0);
- analogWrite(RPWM_Output, 0);
- }
- if (GamePad.isBluePressed()) { // Steer Straight
- SteeringServo.write(90);
- }
- if (GamePad.isOrangePressed()) { // Speed +
- Speed = Speed + 10;
- if (Speed >= MaxSpeed) {
- Speed = MaxSpeed;
- }
- delay(100);
- }
- if (GamePad.isGreenPressed()) { // Speed -
- Speed = Speed - 10;
- if (Speed <= 0) {
- Speed = 0;
- }
- delay(100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement