This was one of those rare times where I had a hunch, followed it, and had a great result.
So for a project I’m working on for school, we have a robot with multiple composite video cameras onboard. We will be using those cameras seen on DIY drones or in simple security systems. We will be transmitting this video feed via a 5.8GHz video transmitter meant for a drone. We want the operator to be able to switch which feed they’re viewing at a given time, but we don’t want to have to use 3 transmitters and receivers. So to get around this, I thought we might just connect video feeds to a simple analog multiplexer I had laying around from a previous project and see if you could switch the feed that way. Turns out, you totally can. Here’s the eventual block diagram of this part of our project if you’re interested:
The following is the code running on the arduino. Remember, this isn’t doing anything special other than driving the mux:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
#define NUMSELECTS 4 int s0 = 2; int s1 = 3; int s2 = 4; int s3 = 5; int selects[NUMSELECTS] = {s0, s1, s2, s3}; int select_state[NUMSELECTS] = {0, 0, 0, 0}; void setup() { Serial.begin(9600); for (int index = 0; index < NUMSELECTS; index++) { pinMode(selects[index], OUTPUT); digitalWrite(selects[index], select_state[index]); } } void loop() { if (Serial.available() > 0) { char inchar = Serial.read(); //assigns one byte (as serial.read()'s only input one byte at a time switch(inchar) { case '0': Serial.println("Switching to video signal 0"); select_state[0] = 0; select_state[1] = 0; select_state[2] = 0; select_state[3] = 0; write_selects(); break; case '1': Serial.println("Switching to video signal 1"); select_state[0] = 1; select_state[1] = 0; select_state[2] = 0; select_state[3] = 0; write_selects(); break; default: Serial.println("Bad input"); break; } } } void write_selects() { for (int index = 0; index < NUMSELECTS; index++) { digitalWrite(selects[index], select_state[index]); } } |