Skip to content
Snippets Groups Projects
Commit 27e9a4f2 authored by DenysVolo's avatar DenysVolo
Browse files

Binary adder files added

parent 29e71a14
No related branches found
No related tags found
No related merge requests found
#include "pico/stdlib.h"
int main() {
int i;
for (i=1;i<10;++i) {
uint init = i;
gpio_init(init);
gpio_set_dir(init, GPIO_OUT);
}
uint binaryZero = 20;
gpio_init(binaryZero);
gpio_set_dir(binaryZero, GPIO_IN);
uint binaryOne = 21;
gpio_init(binaryOne);
gpio_set_dir(binaryOne, GPIO_IN);
int currentOut = 2;
int firstInt = 0;
int secondInt = 0;
while (currentOut < 6) {
if (gpio_get(binaryZero) == 0) {
gpio_put(currentOut,0);
currentOut++;
sleep_ms(250);
} else if (gpio_get(binaryOne) == 0) {
gpio_put(currentOut,1);
firstInt = firstInt + (1<<(5-currentOut));
currentOut++;
sleep_ms(250);
}
}
while (currentOut < 10) {
if (gpio_get(binaryZero) == 0) {
gpio_put(currentOut,0);
currentOut++;
sleep_ms(250);
} else if (gpio_get(binaryOne) == 0) {
gpio_put(currentOut,1);
secondInt = secondInt + (1<<(9-currentOut));
currentOut++;
sleep_ms(250);
}
}
int finalInt = firstInt + secondInt;
currentOut = 1;
while (finalInt != 0) {
if ((finalInt - (1<<(5-currentOut))) > -1) {
gpio_put(currentOut,1);
finalInt = finalInt - (1<<(5-currentOut));
currentOut++;
} else {
gpio_put(currentOut,0);
currentOut++;
}
}
while(currentOut < 10) {
gpio_put(currentOut,0);
currentOut++;
}
}
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment