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)) {
manualDigitalDrive();
//updateTemp();
updateTemp();
String temp_str = "T: " + String(temperature) + " Grad C";
lcdLines[5] = temp_str;
refreshLCD();

4
Code/miniRobotRC/fahrsteuerung_old.ino

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

16
Code/miniRobotRC/temp.ino

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

Loading…
Cancel
Save