Control Lego racer 42065 by M5StickC IR LED
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
#include <M5StickC.h> | |
#include <PowerFunctions.h> | |
PowerFunctions pf(9, 0); | |
#define RED_BUTTON 32 | |
#define BLUE_BUTTON 33 | |
#define ButtonA 37 | |
void setup() { | |
M5.begin(); | |
pinMode(RED_BUTTON, INPUT); | |
pinMode(BLUE_BUTTON, INPUT); | |
pinMode(ButtonA, INPUT); | |
} | |
void loop() { | |
int red=0, blue=0, main=0; | |
blue = digitalRead(BLUE_BUTTON); | |
red = digitalRead(RED_BUTTON); | |
main = digitalRead(ButtonA); | |
if(blue == LOW && red == LOW) { | |
M5.Lcd.fillScreen(TFT_GREEN); | |
step(BLUE, PWM_FWD3); | |
step(RED, PWM_REV3); | |
} | |
else if(blue == LOW) { | |
M5.Lcd.fillScreen(TFT_BLUE); | |
step(BLUE, PWM_FWD3); | |
} | |
else if(red == LOW) { | |
M5.Lcd.fillScreen(TFT_RED); | |
step(RED, PWM_REV3); | |
} | |
else if(main == LOW) { | |
M5.Lcd.fillScreen(TFT_YELLOW); | |
step(BLUE, PWM_REV3); | |
step(RED, PWM_FWD3); | |
} | |
else { | |
M5.Lcd.fillScreen(TFT_BLACK); | |
step(RED, PWM_FLT); | |
step(BLUE, PWM_FLT); | |
} | |
delay(10); | |
} | |
void step(uint8_t output, uint8_t pwm) { | |
pf.single_pwm(output, pwm); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment