Skip to content

Commit

Permalink
Updated firmware to three sensors, added animation
Browse files Browse the repository at this point in the history
  • Loading branch information
wilcotomassen committed Aug 17, 2017
1 parent a981d7a commit 61ebb6a
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions firmware/sensorbridge/sensorbridge.ino
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@

#define SENSOR_COUNT 6
#define STATUS_LED_PIN 7
#define SENSOR_COUNT 3

// Mapping of sensors to pins. The first value of the sensor pin arrays
// is the pin that Sensor1 is connected to, second value for Sensor2 and
// so on.
// Sensor id: 1, 2, 3, 4, 5, 6
uint8_t sensorDataPins[] = { 5, 4, 3, 2, 0, 1 }; // Analog input pin the sensor is connected to
uint8_t sensorConnectionPins[] = { 4, 5, 6, 7, 3, 2 }; // Digital input pin the sensor is connected to
// Sensor id: 1, 2, 3
uint8_t sensorDataPins[] = { 5, 4, 3 }; // Analog input pin the sensor is connected to to collect data
uint8_t sensorConnPins[] = { 2, 3, 4 }; // Digital input pin the sensor is connected to check connection (uses internal pullup)
uint8_t sensorLedPins[] = { 5, 6, 7 }; // Digital input pin the sensor is connected to display connection status

void setup() {

// Setup pin modes for the connection pins
for (int i = 0; i < SENSOR_COUNT; i++) {
pinMode(sensorConnectionPins[i], INPUT);
// Setup pin modes for the digital pins
for (int i = 0; i < SENSOR_COUNT; i++) {
pinMode(sensorConnPins[i], INPUT_PULLUP);
pinMode(sensorLedPins[i], OUTPUT);
}

// Booting LED animation
for (int i = 0; i < 40; i++) {
int enabledLedIndex = i % SENSOR_COUNT;
for (int j = 0; j < SENSOR_COUNT; j++) {
digitalWrite(sensorLedPins[j], j == enabledLedIndex);
}
delay(50);
}
pinMode(STATUS_LED_PIN, OUTPUT);

// Start serial communication
Serial.begin(9600);
@@ -28,7 +37,8 @@ void loop() {
for (int i = 0; i < SENSOR_COUNT; i++) {

// Determine value of pin
bool sensorConnected = digitalRead(sensorConnectionPins[i]);
bool sensorConnected = (digitalRead(sensorConnPins[i]) == LOW); // Pin is pulled low if sensor is connected
digitalWrite(sensorLedPins[i], sensorConnected);
uint16_t value = sensorConnected ? analogRead(sensorDataPins[i]) : 65535;

// Write value to serial port

0 comments on commit 61ebb6a

Please sign in to comment.