/**********************************************************************
Filename : RF24_Remote_Car.ino
Product : Freenove 4WD Car for UNO
Description : A RF24 Remote Car.
Auther : www.freenove.com
Modification: 2020/11/27
**********************************************************************/
#include "Freenove_4WD_Car_for_Arduino.h"
#include "RF24_Remote.h"
#define NRF_UPDATE_TIMEOUT 1000
u32 lastNrfUpdateTime = 0;
#define SERVO_STOP 91
//RDD Add small display screen and code to set it up and use it
#include <Wire.h>
#include "SSD1306AsciiWire.h"
#define I2C_ADDRESS 0x3C
SSD1306AsciiWire oled;
//RDD Add code to use the servo
#include <Servo.h>
Servo servo1;
void setup() {
pinsSetup();
servo1.attach(PIN_SERVO); //RDD
if (!nrf24L01Setup()) {
alarm(3, 2);
}
alarm(2, 1); //RDD
setupScreen(); //RDD Setup screen and print the group number and battery voltage
screenPrint(1,4,"Hello");
screenPrint(3,3,"Display");
screenPrint(4,5,"Demo");
delay(4000);
clearScreen();
screenPrint(1,3,"Group 11");
getBatteryVoltage();
char buffer[6];
dtostrf(batteryVoltage,4,2,buffer);
screenPrint(2,1,buffer);
screenPrint(2,6,"Volts");
screenPrint(3,1,"Mode: Stop");
screenPrint(4,1,"Car Diasbled");
}
void loop() {
if (getNrf24L01Data()) {
clearNrfFlag();
updateCarActionByNrfRemote();
lastNrfUpdateTime = millis();
}
if (millis() - lastNrfUpdateTime > NRF_UPDATE_TIMEOUT) {
lastNrfUpdateTime = millis();
resetNrfDataBuf();
updateCarActionByNrfRemote();
}
}
void setupScreen() {
Wire.begin();
Wire.setClock(400000L);
oled.begin(&Adafruit128x64, I2C_ADDRESS);
oled.clear();
oled.setFont(fixed_bold10x15);
}
void clearScreen() {
oled.clear();
}
void screenPrint(int row, int col, char* value) {
oled.clearField((col - 1) *11, (row - 1) * 2, 12);
oled.print(value);
}
Freenove 4WD Controller and Car Simulator.
Servo angles represent the speed
of the left and right car motors.
Servo Speed
Dial
Car Turning
Speed Dial