Browse Source

Now everything works as expected.

master
nickg 5 years ago
parent
commit
ecd158439b
  1. 5
      Code/miniRobot/miniRobot.ino
  2. 23
      Code/miniRobot/temperatureDistance.ino
  3. 3
      Code/miniRobotRC/_main.ino
  4. 28
      Code/miniRobotRC/fahrsteuerung_old.ino
  5. 29
      Code/miniRobotRC/temp.ino

5
Code/miniRobot/miniRobot.ino

@ -77,7 +77,7 @@ void setup() {
//Temperatur- und Abstandsmessung
setEchoPins(16, 6); //16: A2, 6: D6
setEchoPins(A2, 6); //16: A2, 6: D6
tempDistSetup();
timer = millis();
}
@ -94,7 +94,6 @@ void loop() {
temperature = dallas(4, 0);
measureDistance();
distance = calculateDistance();
Serial.println(distance);
timer = currentMillis;
}
@ -193,6 +192,7 @@ void commandInterpretation() {
forwardA = true;
forwardB = true;
driveOn = false; */
break;
}
@ -200,4 +200,5 @@ void commandInterpretation() {
}
clearCommands();
}

23
Code/miniRobot/temperatureDistance.ino

@ -5,29 +5,31 @@
int trig;
int echo;
uint16_t distance3 = 0;
uint16_t distance2 = 0;
unsigned long distance3 = 0;
unsigned long distance2 = 0;
//ISR for PCINT20
//ISR for PCINT2
ISR(PCINT2_vect) {
distance3 = pulseIn(echo, HIGH);
if(distance3 > 0){
distance2 = distance3;
}
delayMicroseconds(10);
PCICR &= ~0b00000100;
PCICR &= ~0b00000111;
PCMSK2 &= ~0b00010000;
delayMicroseconds(10);
}
void setEchoPins(int pin1, int pin2){
trig = pin1;
echo = pin2;
}
int16_t calculateDistance(){
int16_t result2 = distance2/ 58;
int16_t result2 = (int16_t)(((float) distance2/ 58.0));
if(result2 > maxDistance){
result2 = maxDistance;
}
@ -36,15 +38,17 @@ int16_t calculateDistance(){
void measureDistance(){
digitalWrite(trig, HIGH);
digitalWrite(trig, HIGH);
// ... wait for 10 µs ...
delayMicroseconds(10);
// ... put the trigger down ...
digitalWrite(trig, LOW);
Serial.println("messe...");
PCICR |= 0b00000100;
PCMSK2 |= 0b00010000;
PCMSK2 |= (1 << echo);
}
@ -89,7 +93,6 @@ void tempDistSetup(){
// Reset the trigger pin and wait a half a second
digitalWrite(trig, LOW);
delayMicroseconds(500);
Serial.println(echo);
sei();

3
Code/miniRobotRC/_main.ino

@ -23,14 +23,17 @@ void loop() {
while(!tasten.getButtonCycle(buttonStart)) {
manualDigitalDrive();
updateTemp();
}
tasten.clearButton(buttonStart);
while(!tasten.getButtonCycle(buttonStart)){
motorMapping();
updateTemp();
}
tasten.clearButton(buttonStart);
while(!tasten.getButtonCycle(buttonStart)){
joystickSteuerung(); //TODO ()
updateTemp();
}
tasten.clearButton(buttonStart);

28
Code/miniRobotRC/fahrsteuerung_old.ino

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

29
Code/miniRobotRC/temp.ino

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