Großes Auto, kleine Garage – jeder Zentimeter zählt! Ich möchte mein Auto genau so in der Garage abstellen, dass das Garagentor gerade noch zu geht um vor dem Auto möglichst viel Platz zu haben. Natürlich gibt es dafür die verschiedensten einfachen Methoden. Als Bastler habe ich mich aber für eine Lösung mit Arduino entschieden!
#include <SR04.h>
#include <LedControl.h>
SR04 sr04 = SR04(3, 4);
LedControl lc = LedControl(12, 10, 11, 1);
int distance; // sensor distance
int parkpos; // park distance in front of sensor in cm
int ledbrght; // brightness
// all signs/frames
byte frm_dis_6[8] = { B10000001, B10000001, B10000001, B10000001, B10000001, B10000001, B10000001, B10000001 };
byte frm_dis_5[8] = { B01000001, B01000001, B01000001, B01000001, B01000001, B01000001, B01000001, B01000001 };
byte frm_dis_4[8] = { B00100001, B00100001, B00100001, B00100001, B00100001, B00100001, B00100001, B00100001 };
byte frm_dis_3[8] = { B00010001, B00010001, B00010001, B00010001, B00010001, B00010001, B00010001, B00010001 };
byte frm_dis_2[8] = { B00001001, B00001001, B00001001, B00001001, B00001001, B00001001, B00001001, B00001001 };
byte frm_dis_1[8] = { B00000101, B00000101, B00000101, B00000101, B00000101, B00000101, B00000101, B00000101 };
byte frm_arr_a[8] = { B00001000, B00001100, B11111110, B11111111, B11111110, B00001100, B00001000, B00000000 };
byte frm_arr_b[8] = { B00010000, B00110000, B01111111, B11111111, B01111111, B00110000, B00010000, B00000000 };
byte frm_stop[8] = { B00111100, B01111110, B11111111, B11111111, B11111111, B11111111, B01111110, B00111100 };
void writeSign(byte arr[8]) {
for (int i = 0; i < 8; i++) {
lc.setRow(0, i, arr[i]);
}
}
void setup() {
// start MAX72xx, set brightness and clear display
lc.shutdown(0, false);
lc.setIntensity(0, 5);
lc.clearDisplay(0);
Serial.begin(9600);
delay(1000);
}
void loop() {
// read poti B and set led intensity
ledbrght = analogRead(A7);
ledbrght = ledbrght/75; // 0 - 15
lc.setIntensity(0, ledbrght);
// read distance in cm
distance = sr04.Distance();
// read poti A and set park position in cm
parkpos = analogRead(A3);
parkpos = parkpos/5.2 + 10; // 10 - 200
// tha rocket science magic ;)
if (distance < 200 + parkpos && distance >= 30 + parkpos) { writeSign(frm_arr_a); }
else if (distance < 30 + parkpos && distance >= 25 + parkpos) { writeSign(frm_dis_6); }
else if (distance < 25 + parkpos && distance >= 20 + parkpos) { writeSign(frm_dis_5); }
else if (distance < 20 + parkpos && distance >= 15 + parkpos) { writeSign(frm_dis_4); }
else if (distance < 15 + parkpos && distance >= 10 + parkpos) { writeSign(frm_dis_3); }
else if (distance < 10 + parkpos && distance >= 5 + parkpos) { writeSign(frm_dis_2); }
else if (distance < 5 + parkpos && distance >= parkpos) { writeSign(frm_dis_1); }
else if (distance < parkpos && distance >= -5 + parkpos) { writeSign(frm_stop); }
else if (distance < -5 + parkpos ) { writeSign(frm_arr_b); }
else { lc.clearDisplay(0); }
delay(100);
}
Gehäuse und weitere Infos folgen…