Skip to content

Instantly share code, notes, and snippets.

@mokjpn
Last active October 3, 2021 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mokjpn/e1e089a0dcf1c14ce16d630108f3257c to your computer and use it in GitHub Desktop.
Save mokjpn/e1e089a0dcf1c14ce16d630108f3257c to your computer and use it in GitHub Desktop.
Control Lego racer 42065 by M5StickC IR LED
#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