Browse Source

Temperature is now shown on the lcd! Amazing! Wow, very cool.

master
nickg 5 years ago
parent
commit
ebed7f2188
  1. 13
      Code/miniRobot/miniRobot.ino
  2. 6
      Code/miniRobotRC/JoystickSteuerung.ino
  3. 2
      Code/miniRobotRC/_main.ino
  4. 25
      Code/miniRobotRC/fahrsteuerung_old.ino
  5. 2
      Code/miniRobotRC/funkInit.ino
  6. 3
      Code/miniRobotRC/miniRobotRC.ino

13
Code/miniRobot/miniRobot.ino

@ -23,6 +23,7 @@ void inline clearCommands() {
} }
const byte address[6] = "00001"; const byte address[6] = "00001";
const byte address2[6] = "00002";
//Kommandos //Kommandos
#define nothing 9 //reset/nichts tun #define nothing 9 //reset/nichts tun
#define speedA 1 // set speed A + speed #define speedA 1 // set speed A + speed
@ -60,7 +61,7 @@ bool forwardA = true;
bool forwardB = true; bool forwardB = true;
volatile bool driveOn = false; volatile bool driveOn = false;
int temperatur = 0;
int16_t temperatur = 0;
volatile long driveTimeout = 0; volatile long driveTimeout = 0;
@ -71,6 +72,7 @@ void setup() {
// motorA.setPWM16(2,RESOLUTION); // motorA.setPWM16(2,RESOLUTION);
// motorB.setPWM16(2,RESOLUTION); // motorB.setPWM16(2,RESOLUTION);
radio.begin(); radio.begin();
radio.openWritingPipe(address2);
radio.openReadingPipe(0, address); radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MAX); radio.setPALevel(RF24_PA_MAX);
radio.startListening(); radio.startListening();
@ -83,6 +85,7 @@ void setup() {
} }
void loop() { void loop() {
Serial.println(temperature);
if (radio.available()) { if (radio.available()) {
radio.read(&commands, sizeof(commands)); radio.read(&commands, sizeof(commands));
commandInterpretation(); commandInterpretation();
@ -92,9 +95,11 @@ void loop() {
pwmA = 0; pwmA = 0;
pwmB = 0; pwmB = 0;
} }
drive.setPWM_A(pwmA); drive.setPWM_A(pwmA);
drive.setPWM_B(pwmB); drive.setPWM_B(pwmB);
//Temperatur- und Abstandsmessung //Temperatur- und Abstandsmessung
temperature = dallas(4, 0); temperature = dallas(4, 0);
@ -150,8 +155,10 @@ void commandInterpretation() {
break; break;
} }
case getTemp : { case getTemp : {
radio.write(&temperature, sizeof(temperature));
Serial.println("Senden!");
radio.stopListening();
radio.write(&temperature, sizeof(int16_t));
radio.startListening();
break; break;
} }
case timeToDrive : { case timeToDrive : {

6
Code/miniRobotRC/JoystickSteuerung.ino

@ -64,11 +64,5 @@ void joystickInit() {
commands[7] = highByte(driveTimeout); commands[7] = highByte(driveTimeout);
commands[8] = lowByte(driveTimeout); commands[8] = lowByte(driveTimeout);
commands[9] = goDrive; commands[9] = goDrive;
commands[10] = getTemp;
commands[11] = highByte(temperature);
commands[12] = lowByte(temperature);
commands[13] = getTemp;
commands[14] = highByte(distance);
commands[15] = lowByte(distance);
radio.write(&commands, sizeof(commands)); radio.write(&commands, sizeof(commands));
} }

2
Code/miniRobotRC/_main.ino

@ -20,6 +20,7 @@ void setup() {
void loop() { void loop() {
//lcdMenu(); //lcdMenu();
while(!tasten.getButtonCycle(buttonStart)) { while(!tasten.getButtonCycle(buttonStart)) {
manualDigitalDrive(); manualDigitalDrive();
} }
@ -32,6 +33,7 @@ void loop() {
joystickSteuerung(); //TODO () joystickSteuerung(); //TODO ()
} }
tasten.clearButton(buttonStart); tasten.clearButton(buttonStart);
} }
void lcdMenu() { void lcdMenu() {

25
Code/miniRobotRC/fahrsteuerung_old.ino

@ -1,4 +1,5 @@
void manualDigitalDrive() { void manualDigitalDrive() {
bool goOn = false; bool goOn = false;
String temp_str = "T: " + String(temperature) + " Grad C"; String temp_str = "T: " + String(temperature) + " Grad C";
lcdLines[5] = temp_str; lcdLines[5] = temp_str;
@ -48,6 +49,30 @@ void manualDigitalDrive() {
radio.write(&commands, sizeof(commands)); radio.write(&commands, sizeof(commands));
goOn = false; goOn = false;
} }
//Temperatur <3
if((millis() - temp_time) >= 5000){ // jede Sekunden
temp_time = millis();
bool err = false;
clearCommands();
commands[0] = getTemp;
radio.write(&commands, sizeof(commands) && !err);
long start = micros();
radio.startListening();
while(!radio.available()){
//Serial.println("nix");
if((micros()- start) >= 1){
err = true;
}
}
if(!err){
radio.read(&temperature, sizeof(int16_t));
}
radio.stopListening();
}
// } // }
// tasten.clearAllButtons(); // tasten.clearAllButtons();
} }

2
Code/miniRobotRC/funkInit.ino

@ -1,6 +1,8 @@
void funkInit() { void funkInit() {
radio.begin(); radio.begin();
radio.openWritingPipe(address); radio.openWritingPipe(address);
radio.openReadingPipe(0, address2);
radio.setPALevel(RF24_PA_MAX); radio.setPALevel(RF24_PA_MAX);
radio.stopListening(); radio.stopListening();
} }

3
Code/miniRobotRC/miniRobotRC.ino

@ -42,6 +42,8 @@ uint16_t driveTimeout = 0;
int16_t distance; int16_t distance;
int16_t temperature = 0; int16_t temperature = 0;
int16_t temp_time = millis();
//Funk //Funk
#include <SPI.h> #include <SPI.h>
#include <nRF24L01.h> #include <nRF24L01.h>
@ -50,5 +52,6 @@ int16_t temperature = 0;
RF24 radio(A2, A3); // CE, CSN RF24 radio(A2, A3); // CE, CSN
const byte address[6] = "00001"; const byte address[6] = "00001";
const byte address2[6] = "00002";
uint8_t commands[32]; uint8_t commands[32];
Loading…
Cancel
Save