#include <stdio.h>
#include "pico/stdlib.h"
#define RGB_BASE_PIN 17
const uint32_t RGB_MASK = 1 << RGB_BASE_PIN | // Pin 17
1 << RGB_BASE_PIN + 1 | // Pin 18
1 << RGB_BASE_PIN + 2; // Pin 19
int main() {
stdio_init_all();
// Enable pins 17, 18 & 19 as input
gpio_init_mask(RGB_MASK);
uint32_t gpio;
while (true) {
// Extract desired bits from GPIO with RGB_MASK and shift right
// This gives us a 3 bit value in the form 0b<b><g><r>
gpio = (gpio_get_all() & RGB_MASK) >> RGB_BASE_PIN;
// Perform comparisons on the 3 bits to determine the state of the RGB LED
switch(gpio) {
case 0b110: // red
printf("off\n");
break;
case 0b100: // yellow
printf("optical\n");
break;
case 0b000: // white
printf("aux\n");
break;
case 0b101: // green
printf("line-in\n");
break;
case 0b011: // blue
printf("bluetooth\n");
break;
case 0b111: // off
printf("none\n");
break;
default:
printf("unknown\n");
}
sleep_ms(500);
}
return 0;
}
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
rgb1:R
rgb1:COM
rgb1:G
rgb1:B
r1:1
r1:2
r2:1
r2:2
r3:1
r3:2
sw1:1
sw1:2
sw1:3
sw2:1
sw2:2
sw2:3
sw3:1
sw3:2
sw3:3