Ein Roboter mit bürstenlosem Antrieb, differenzial und NRF24L01 Funk. Großflächig gebaut um ein großes Solarpanel aufzunehmen. https://gitlab.informatik.hs-fulda.de/fdai5253/roboter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.0 KiB

  1. #include <OneWire.h>
  2. int16_t dallas(int x, byte start){
  3. OneWire ds(x);
  4. byte i;
  5. byte data[2];
  6. int16_t result;
  7. do{
  8. ds.reset();
  9. ds.write(0xCC); //skip Command
  10. ds.write(0xBE); //Read 1st 2 bytes of Scratchpad
  11. result = 0;
  12. for(i = 0; i < 2; i++){
  13. data[i] = ds.read();
  14. }
  15. result = (data[1]<<8)|data[0];
  16. result = result/16; //DS1820 2 DS18B20 16
  17. ds.reset();
  18. ds.write(0xCC);
  19. ds.write(0x44, 1); //start conversion
  20. if(start){
  21. delay(1000);
  22. }
  23. } while(start--);
  24. return result;
  25. }
  26. void tempDistSetup(){
  27. dallas(4, 1);
  28. }
  29. void runMeasurements(){
  30. long run_time = micros();
  31. if(millis() - timer >= 100){
  32. measureDistance();
  33. timer = millis();
  34. }
  35. Serial.print("Temperatur: ");
  36. Serial.println(dallas(4, 0));
  37. Serial.print("Distanz: ");
  38. Serial.print(calculateDistance());
  39. Serial.println("cm");
  40. run_time = micros() - run_time;
  41. Serial.print("Zeit für Durchlauf: ");
  42. Serial.println(run_time);
  43. Serial.println();
  44. delay(1000);
  45. }