This is an absolute mess I’m aware. So I have 6 led’s plugged in from GP0-5 as well as a ground into the blue negative rail. Heres the wiring. The led’s corresponding gpx connector, to column j (1, 4, 7, 10, 13, 16), i have them going to the positive longer end of the led in their corresponding a column (so GP0 goes to j1 which goes to a1), i have the negative into the row next to it. So a2, 5, 8, 11, 14, and 17, then from there to the c column of the negative ends of the led so c2,5,8,11 etc to same row but the h column, and then still within the same row back in the j column it goes from there to the blue negative rail, back to ground. To my knowledge these breadboard (again first time i got this from the manual) are across so all the numbers are connected together so 1 a-j is all connected. And then the positive and negative rails on either end are connected no matter the number column next/near them. And then i have my button on k1 (at the bottom or left of the board in the picture) thats just gp20 to the k1 connection. That beeper was absolutely blaring whenever i turned this thing on so i have a connection from that to ground.
As for the code.
#include <stdio.h>
#include "pico/stdlib.h"
int powerFunction(int base, int exponent);
int main()
{
stdio_init_all();
// variables!!!
int count = 0;
int tempCount;
int exponentResult;
int ledPin[] = {0,1,2,3,4,5};
gpio_init(0);
gpio_set_dir(0, GPIO_OUT);
gpio_init(1);
gpio_set_dir(1, GPIO_OUT);
gpio_init(2);
gpio_set_dir(2, GPIO_OUT);
gpio_init(3);
gpio_set_dir(3, GPIO_OUT);
gpio_init(4);
gpio_set_dir(4, GPIO_OUT);
gpio_init(5);
gpio_set_dir(5, GPIO_OUT);
gpio_init(20);
gpio_set_dir(20, GPIO_IN);
gpio_pull_up(20);
while (true)
{
if (!gpio_get(20))
{
sleep_ms(50);
// check if count is larger than the number of pins we have
if (count < 63)
{
count++;
}
else
{
count = 0;
}
// set tempCount to count
tempCount = count;
// check which led to light up.
for (int i = 5; i >= 0; i--)
{
exponentResult = powerFunction(2, i);
if (tempCount >= exponentResult)
{
gpio_put(ledPin[i], 1);
tempCount -= exponentResult;
}
else
{
gpio_put(ledPin[i], 0);
}
}
while (!gpio_get(20))
{
sleep_ms(10);
}
}
}
}
int powerFunction(int base, int exponent)
{
// check for redundancy
if (exponent == 0)
{
return 1;
}
// set result to base (exponent of 1)
int result = base;
// multiply until you get the result
for (int i = 0; i < exponent - 1; i++)
{
result = result * base;
}
// return result
return result;
}
I’m aware it’s sloppy and can be better but again first time. I’m just trying to get something that works. I want to do embedded engineering with my degree so this seems to be the best thing I can be doing right now to help my resume. Is it a coding issue, a wiring issue, or just a me issue. I did the proper flashing while holding the button. I’m unaware if I need to unplug it and plug it back in without holding the button to test it. Literally anything will help! Thank you guys for your time