2 Commits

  1. 64
      Code/miniRobot/distance.ino
  2. 2
      Code/miniRobotRC/_main.ino
  3. 4
      Code/miniRobotRC/fahrsteuerung_old.ino
  4. 16
      Code/miniRobotRC/temp.ino

64
Code/miniRobot/distance.ino

@ -0,0 +1,64 @@
#define maxDistance 400
int trig;
int echo;
//ISR for PCINT2
ISR(PCINT2_vect) {
if((PIND & 64) > 0) {
pulseStart = micros();
} else {
startNewMeasurement = true;
pulseLength = micros() - pulseStart;
newResult = true;
}
PCIFR = 0;
}
void setEchoPins(int pin1, int pin2){
trig = pin1;
echo = pin2;
PCIFR = 0;
PCICR |= 0b00000100;
PCMSK2 |= (1 << echo);
// Initializing Trigger Output and Echo Input
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
// Reset the trigger pin and wait a half a second
digitalWrite(trig, LOW);
delayMicroseconds(500);
}
int16_t calculateDistance(){
int16_t result = 1;
if(pulseLength > 0) {
result = (int16_t)(pulseLength / 58);
}
if(result > maxDistance){
result = maxDistance;
}
newResult = false;
//Serial.println(result);
return result;
}
void measureDistance(){
digitalWrite(trig, HIGH);
// ... wait for 10 µs ...
delayMicroseconds(10);
// ... put the trigger down ...
digitalWrite(trig, LOW);
//Serial.println("messe...");
startNewMeasurement = false;
}

2
Code/miniRobotRC/_main.ino

@ -23,7 +23,7 @@ void loop() {
while(!tasten.getButtonCycle(buttonStart)) { while(!tasten.getButtonCycle(buttonStart)) {
manualDigitalDrive(); manualDigitalDrive();
//updateTemp();
updateTemp();
String temp_str = "T: " + String(temperature) + " Grad C"; String temp_str = "T: " + String(temperature) + " Grad C";
lcdLines[5] = temp_str; lcdLines[5] = temp_str;
refreshLCD(); refreshLCD();

4
Code/miniRobotRC/fahrsteuerung_old.ino

@ -1,7 +1,6 @@
void manualDigitalDrive() { void manualDigitalDrive() {
bool goOn = false; bool goOn = false;
// while(!tasten.getButtonCycle(buttonL1)) {
clearCommands(); clearCommands();
if(!tasten.getAnyPressed()) { if(!tasten.getAnyPressed()) {
lcdLines[0] = "Warte..."; lcdLines[0] = "Warte...";
@ -47,7 +46,4 @@ void manualDigitalDrive() {
radio.write(&commands, sizeof(commands)); radio.write(&commands, sizeof(commands));
goOn = false; goOn = false;
} }
// }
// tasten.clearAllButtons();
} }

16
Code/miniRobotRC/temp.ino

@ -1,28 +1,24 @@
//Temperatur <3 //Temperatur <3
void updateTemp(){ void updateTemp(){
unsigned long currentMillis = millis();
if((unsigned long)(currentMillis - temp_time) >= 1000){ // jede Sekunden
if((unsigned long)(millis() - temp_time) >= 1000){ // jede Sekunden
temp_time = millis(); temp_time = millis();
bool err = false; bool err = false;
clearCommands(); clearCommands();
commands[0] = getTemp; commands[0] = getTemp;
radio.write(&commands, sizeof(commands) /* && !err */);
radio.write(&commands, sizeof(commands));
unsigned long start = micros(); unsigned long start = micros();
radio.startListening(); radio.startListening();
while(!radio.available()){ while(!radio.available()){
//Serial.println("nix"); //Serial.println("nix");
unsigned long currentMicros = micros();
/* unsigned long currentMicros = micros();
if((unsigned long)(currentMicros - start) >= 1){ if((unsigned long)(currentMicros - start) >= 1){
err = true; err = true;
} */
if((millis() - temp_time) >= 10) break;
} }
/*
int16_t readData;
radio.read(&readData, sizeof(int16_t));
temperature = readData; */
}
if(!err){
if(/* !err */ true){
int16_t readData; int16_t readData;
radio.read(&readData, sizeof(int16_t)); radio.read(&readData, sizeof(int16_t));
temperature = readData; temperature = readData;

Loading…
Cancel
Save