Compare commits
No commits in common. "f6bb0877991e142b6d57e77284a7cf27264945c8" and "b5ba5f6f9e94344ce5b61f85331243f499457840" have entirely different histories.
f6bb087799
...
b5ba5f6f9e
|
@ -1,7 +0,0 @@
|
||||||
# To install on robot
|
|
||||||
|
|
||||||
```
|
|
||||||
git clone <url>
|
|
||||||
cd lewis-crawler/crawler_software/raspberry_pi
|
|
||||||
make install?
|
|
||||||
```
|
|
|
@ -10,28 +10,27 @@
|
||||||
// This servo is used to wipe and clean the camera lens
|
// This servo is used to wipe and clean the camera lens
|
||||||
Servo windowWiperServo;
|
Servo windowWiperServo;
|
||||||
|
|
||||||
// Variables populated over i2c from master
|
// This is a variable capable of storing up to 4 items
|
||||||
int id;
|
char instruction[32] = "";
|
||||||
int val;
|
|
||||||
|
// Values for the id, and raw value of an instruction
|
||||||
|
char * id;
|
||||||
|
char * raw_value;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// For debugging
|
|
||||||
//Serial.begin(115200);
|
|
||||||
|
|
||||||
// Attach the wiper servo to pin 9
|
// Attach the wiper servo to pin 9
|
||||||
windowWiperServo.attach(9);
|
windowWiperServo.attach(9);
|
||||||
|
|
||||||
|
// This is only useful for debugging
|
||||||
|
//Serial.begin(9600);
|
||||||
|
|
||||||
// This is the address the pi will speak to us at
|
// This is the address the pi will speak to us at
|
||||||
Wire.begin(0x4);
|
Wire.begin(0x4);
|
||||||
|
|
||||||
// Call receiveEvent when data received
|
// Call receiveEvent when data received
|
||||||
Wire.onReceive(receiveEvent);
|
Wire.onReceive(receiveEvent);
|
||||||
|
|
||||||
// Setup LED
|
//Serial.println("Finished Setup.");
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
|
||||||
|
|
||||||
//Serial.println("Started");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just loop to keep the running code alive, and wait for events to happen.
|
// Just loop to keep the running code alive, and wait for events to happen.
|
||||||
|
@ -41,20 +40,27 @@ void loop() {
|
||||||
|
|
||||||
// This method runs when we receive a message
|
// This method runs when we receive a message
|
||||||
void receiveEvent(int n) {
|
void receiveEvent(int n) {
|
||||||
Wire.read();
|
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
for (int i = 0; i < n; i++) {
|
||||||
if (true) { // Dont do anything if this is not true
|
instruction[i] = Wire.read();
|
||||||
id = Wire.read(); // ID of the servo/device to access
|
instruction[i + 1] = '\0'; //add null after ea. char
|
||||||
val = Wire.read(); // Value to assign
|
}
|
||||||
|
|
||||||
|
//RPi first byte is cmd byte so shift everything to the left 1 pos so temp contains our string
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
instruction[i] = instruction[i + 1];
|
||||||
|
|
||||||
|
id = strtok (instruction, "-");
|
||||||
|
raw_value = strtok (NULL, "-");
|
||||||
|
|
||||||
|
int value = atoi(raw_value);
|
||||||
|
|
||||||
//Serial.println(id);
|
//Serial.println(id);
|
||||||
//Serial.println(val);
|
//Serial.println(value);
|
||||||
|
|
||||||
switch(id) {
|
// Switch statements dont work on char *
|
||||||
case 1:
|
if (strcmp(id,"WIPE") == 0) // if id, and WIPE cancel out
|
||||||
windowWiperServo.write(val);
|
{
|
||||||
break;
|
windowWiperServo.write(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue