MatrixMiniR4 1.1.5
Matrix Mini R4 Arduino Library API Documentation
Loading...
Searching...
No Matches
MatrixMiniR4.cpp
Go to the documentation of this file.
1
15#include "MatrixMiniR4.h"
16#include "Modules/MMLower.h"
17
19
30{
31 MMLower::RESULT result = mmL.Init();
32
33 LED.begin(7);
34 LED.setColor(1, 0, 0, 0);
35 LED.setColor(2, 0, 0, 0);
36 Buzzer.begin(6);
37
38 while (!M1.begin());
39 while (!M2.begin());
40 while (!M3.begin());
41 while (!M4.begin());
42
43 RC1.begin();
44 RC2.begin();
45 RC3.begin();
46 RC4.begin();
47
48 OLED = Adafruit_SSD1306(128, 32, &Wire1, -1);
50 OLED.setTextColor(SSD1306_WHITE); //Default Color White
52 OLED.display();
53
54 /* CLK: D3R(11) , CMD: D2R(4) , SET: D3L(12) , DAT: D2L(5) */
55 PS2.config_gamepad(11, 4, 12, 5, false, false);
56
57 //Check the Init is ok or not.
58 if (result != MMLower::RESULT::OK) {
59 OLED.setCursor(4, 8);
61 OLED.print(F("Init Error"));
62 OLED.display();
63 while (true) {
64 for (uint8_t i = 0; i < 3; i++) {
65 Buzzer.Tone(700, 100);
66 delay(100);
67 Buzzer.NoTone();
68 delay(100);
69 }
70 delay(3000);
71 }
72 }
73
74 //Check the FW version is outdated or not.
75 String FWVersion_S;
76 MMLower::RESULT resultFWCheck = mmL.GetFWVersion(FWVersion_S);
77 if (result == MMLower::RESULT::OK) {
78 uint8_t FWmajorVersion, FWminorVersion;
79 uint8_t FWVersion_dotIndex = FWVersion_S.indexOf('.');
80 if (FWVersion_dotIndex != -1) {
81 FWmajorVersion = FWVersion_S.substring(0, FWVersion_dotIndex).toInt();
82 FWminorVersion = FWVersion_S.substring(FWVersion_dotIndex + 1).toInt();
83 if (FWmajorVersion < 3 || (FWmajorVersion == 3 && FWminorVersion < 40)) {
85 OLED.setCursor(11, 5);
86 OLED.print(F("Firmware Outdated!"));
87 OLED.setCursor(11, 18);
88 OLED.print(F("-Press UP to Skip-"));
89 OLED.display();
90 for (uint8_t i = 0; i < 3; i++) {
91 Buzzer.Tone(500, 100);
92 delay(100);
93 Buzzer.NoTone();
94 delay(100);
95 }
96 while (BTN_UP.getState() == false) {
97 delay(1);
98 }
100 OLED.display();
101 }
102 }
103 }
104
105 return true;
106}
107
MMLower mmL(8, 9, 57600)
Handling the Lower MCU (STM32) communication.
MatrixMiniR4 MiniR4
The MiniR4 Main Object.
Header file for the MatrixMiniR4 system, integrating various hardware modules such as motors,...
#define MATRIXMINIR4_OLED_ADDRESS
#define SSD1306_WHITE
Draw 'on' pixels.
Definition MiniR4OLED.h:102
#define SSD1306_SWITCHCAPVCC
Gen. display voltage from 3.3V.
Definition MiniR4OLED.h:131
void setTextSize(uint8_t s)
Set text 'magnification' size. Each increase in s makes 1 pixel that much bigger.
void setTextColor(uint16_t c)
Set text font color with transparant background.
Definition MiniR4_GFX.h:170
void setCursor(int16_t x, int16_t y)
Set text cursor location.
Definition MiniR4_GFX.h:156
Class that stores state and functions for interacting with SSD1306 OLED displays.
Definition MiniR4OLED.h:160
void display(void)
Push data currently in RAM to SSD1306 display.
bool begin(uint8_t switchvcc=SSD1306_SWITCHCAPVCC, uint8_t i2caddr=0, bool reset=true, bool periphBegin=true)
Allocate RAM for image buffer, initialize peripherals and pins.
void clearDisplay(void)
Clear contents of display buffer (set all pixels to off).
RESULT GetFWVersion(String &version)
Definition MMLower.cpp:953
RESULT Init(uint32_t timeout_ms=1000)
Definition MMLower.cpp:15
Main class for the MatrixMiniR4 system.
MiniR4RC< 3 > RC3
Port RC3 RC 5V Servo.
MiniR4DC< 1 > M1
Port M1 DC 5V Motor.
MiniR4RC< 4 > RC4
Port RC4 RC 5V Servo.
PS2X PS2
MJ2 or PS2 (4p DAT CMD to D2, 2p CS CLK to D3)
MiniR4DC< 2 > M2
Port M2 DC 5V Motor.
MiniR4LED LED
Built-in RGB LED.
MiniR4RC< 2 > RC2
Port RC2 RC 5V Servo.
MiniR4DC< 4 > M4
Port M4 DC 5V Motor.
MiniR4BTN< 2 > BTN_UP
Up Button.
Adafruit_SSD1306 OLED
Built-in OLED.
bool begin()
Initialize the MatrixMiniR4 system and its components.
MiniR4DC< 3 > M3
Port M3 DC 5V Motor.
MiniR4RC< 1 > RC1
Port RC1 RC 5V Servo.
MiniR4BUZZER Buzzer
Built-in Buzzer.
bool getState(void)
Retrieves the current state of the button.
Definition MiniR4BTN.h:34
void Tone(uint16_t frequency, uint32_t duration)
Generates a tone at the specified frequency for a given duration.
void NoTone(void)
Stops the tone on the buzzer.
void begin(uint8_t pin)
Initializes the buzzer by setting the pin number. (Built Buzzer at Uno Pin 6)
bool begin(void)
Initializes the DC motor settings.
Definition MiniR4DC.h:35
bool setColor(uint8_t idx, uint32_t rgb)
Sets the color of the LED.
Definition MiniR4LED.h:56
void begin(uint8_t pin)
Initializes the LED. (Built-in at Uno Pin 7)
Definition MiniR4LED.h:26
bool begin(void)
Initializes the servo with a default angle range.
Definition MiniR4RC.h:33
byte config_gamepad(uint8_t, uint8_t, uint8_t, uint8_t)
Configures the gamepad.