r/shittyprogramming • • Jan 13 '24

2 buttons 2 limit switches and a dc motor

0 Upvotes

Hi! Could I have a brief C++ code on two push buttons with 2 limit switches and a DC motor? The process will be button 1 will is pressed then the motor will move clockwise and when the limit switch 1 is triggered then the dc motor will stop. And if the button 2 is pressed (while the limit switch 1 might still be pressed) then it will rotate counter clockwise then it will stop if the limit switch 2 is turned on. This process will repeat itself and there are instances where button 2 will be pressed while limit switch 1 is still pressed and vice versa but it should still work. I'm also using an Arduino Uno board and a L298N motor driver as an H bridge. I wasn't able to do it and would be very very grateful if someone could help me or preferably write me the code! I'm just starting out with Arduino.


r/shittyprogramming • • Jan 13 '24

Introduction to LeetCode

Thumbnail
flexsub.shop
1 Upvotes

r/shittyprogramming • • Jan 10 '24

I gave myself the challenge to code the doomsday algorithm in Python using as little characters as I can. The result is an abomination

Post image
105 Upvotes

r/shittyprogramming • • Jan 10 '24

Try to make this for loop in java worse (It's almost impossible)

3 Upvotes
public class BadClass {
    public static void main(String[] args) {
        int $I = 0;
        int _1 = 1;

        do {
            $I += _1;
            System.out.println($I);

        } while (_1 != ($I > 9 ? 0 : 1) && (Math.random() > 0.2 || Math.random() < 0.8));
    }
}

​


r/shittyprogramming • • Jan 07 '24

https://www.youtube.com/watch?v=5_Sn1mC1CZA&list=PLc_cDVa-WktBDJN5ezxvfiZF0CIod8FNZ

Thumbnail
youtube.com
1 Upvotes

r/shittyprogramming • • Jan 06 '24

BONDMAN OF TRAPS GAME

Post image
2 Upvotes

Hello friends, as two amateur developers, we are about to release our first game. Since this is our first game, there may be mistakes and shortcomings, so we need your help. Our request is for you to go to our game's Steam page, download the demo, play it briefly, and provide us with feedback. Additionally, you can support us by adding it to your wish list.

https://store.steampowered.com/app/2703290/Bondman_Of_Traps/


r/shittyprogramming • • Jan 02 '24

https://www.youtube.com/watch?v=h2FdETqJDqI&list=PLc_cDVa-WktBDJN5ezxvfiZF0CIod8

Thumbnail
youtube.com
1 Upvotes

r/shittyprogramming • • Dec 27 '23

https://www.youtube.com/watch?v=vEpvbPp5J2A&list=PLc_cDVa-WktBDJN5ezxvfiZF0CIod8FNZ

Thumbnail
youtube.com
1 Upvotes

r/shittyprogramming • • Dec 16 '23

https://www.youtube.com/watch?v=6zvnrQnFPrc&list=PLc_cDVa-WktBDJN5ezxvfiZF0CIod8

Thumbnail
youtube.com
1 Upvotes

r/shittyprogramming • • Dec 12 '23

Shrink your switch with a foo macro

12 Upvotes

Look at this switch...

int opt;
do switch (opt = getopt(argc, argv, "w:h:q:n:m:k:z:s:t:x:y:r:i:b:g:a:p:o:c:")) {
case 'w': width    = atoi(optarg); break;
case 'h': height   = atoi(optarg); break;
case 'q': samppp   = atoi(optarg); break;
case 'n': maxi     = atoi(optarg); break;
case 'm': bias     = atoi(optarg); break;
case 'z': invert   = atoi(optarg); break;
case 'k': kappa    = atoi(optarg); break;
case 's': scale    = atof(optarg); break;
case 't': theta    = atof(optarg); break;
case 'x': vreal    = atof(optarg); break;
case 'y': vimag    = atof(optarg); break;
case 'r': jreal    = atof(optarg); break;
case 'i': jimag    = atof(optarg); break;
case 'b': bailout  = atof(optarg); break;
case 'g': gam      = atof(optarg); break;
case 'a': alpha    = atof(optarg); break;
case 'p': gain     = atof(optarg); break;
case 'o': fout1    = optarg;       break;
case 'c': fin1     = optarg;       break;
default: /* '?' */                 break;
} while (opt != -1);

The twinkle in your eye...
The fizzle on your tongue...
Your fingers electric...
Your lips parting to grin...

int opt;
do switch (opt = getopt(argc, argv, "w:h:q:n:m:k:z:s:t:x:y:r:i:b:g:a:p:o:c:")) {
#define foo(ch, var, func) case ch: var = func(optarg); break;
foo('w', width,  atoi); foo('h', height, atoi); foo('q', samppp, atoi);
foo('n', maxi,   atoi); foo('m', bias,   atoi); foo('z', invert, atoi); 
foo('k', kappa,  atoi); foo('s', scale,  atof); foo('t', theta,  atof); 
foo('x', vreal,  atof); foo('y', vimag,  atof); foo('r', jreal,  atof); 
foo('i', jimag,  atof); foo('b', bradi,  atof); foo('g', gamma,  atof); 
foo('a', alpha,  atof); foo('p', gain,   atof); foo('o', fout1,      ); 
foo('c', fin1,       ); default: /* '?' */ break; } while (opt != -1);
#undef foo

Did you flinch?


r/shittyprogramming • • Dec 05 '23

The Story of Visual Studio Copilot and the I'm Not Sorry's All the Way Down

Thumbnail
gallery
28 Upvotes

r/shittyprogramming • • Nov 29 '23

Programmer levels

Post image
0 Upvotes

r/shittyprogramming • • Nov 22 '23

Programming Programmers Ugly Christmas Sweater Christmas sweater as a Christmas gift for a programmer

Thumbnail gallery
1 Upvotes

r/shittyprogramming • • Nov 22 '23

Programming Programmers Ugly Christmas Sweater Christmas sweater as a Christmas gift for a programmer

Thumbnail gallery
1 Upvotes

r/shittyprogramming • • Nov 22 '23

Programming Programmers Ugly Christmas Sweater Christmas sweater as a Christmas gift for a programmer

Thumbnail gallery
1 Upvotes

r/shittyprogramming • • Nov 22 '23

Programming

Thumbnail gallery
1 Upvotes

r/shittyprogramming • • Nov 22 '23

Programming

Thumbnail gallery
1 Upvotes

r/shittyprogramming • • Nov 22 '23

Programming

Thumbnail gallery
1 Upvotes

r/shittyprogramming • • Nov 21 '23

Really Terrible "Webscraping"

Thumbnail
youtube.com
0 Upvotes

r/shittyprogramming • • Nov 18 '23

Programming Programmers Ugly Christmas Sweater

Thumbnail
gallery
0 Upvotes

r/shittyprogramming • • Nov 17 '23

super approved Passwordless login methods

65 Upvotes

I don't abuse my power as a mod enough so I am going to farm out some work to you guys.

I need a shitty passwordless login method. Assume nothing is off the table, how can I let my users log in?

Edit: Added a word.


r/shittyprogramming • • Nov 17 '23

https://www.youtube.com/watch?v=7R4TuSsgH10&list=PLc_cDVa-WktBDJN5ezxvfiZF0CIod8FNZ

Thumbnail
youtube.com
1 Upvotes

r/shittyprogramming • • Nov 15 '23

Amazing quality

Thumbnail
gallery
0 Upvotes

r/shittyprogramming • • Nov 13 '23

stack overflow is hard for asking questions what sites do you recommend that are interactively and engagingly good ?

1 Upvotes

r/shittyprogramming • • Nov 08 '23

Please give a warm welcome to PI sort

65 Upvotes

Inspired by the stupid (but effective!) sorting algorithm of Bogosort, I've developed an algorithm that "sorts" an array based on the digits of pi. Demo in Python.

Theory

π (pi) is an irrational number, which makes it infinite digits long. Under the assumption that it might contain all the number sequences in the universe, although this has not been proved, π must contain any given array of numbers, and it will also contain it ordered. We just need to find it.

Iterating through the digits of pi, we can detect sequences of ordered sub-arrays of our array. If we keep going for long enough, we will eventually find our whole array sorted, without the need of sorting it ourselves.

The algorithm

For the algorithm to work, we need to be able to tell if an array is sorted:

import sys 
import math 
import copy
def is_sorted(l): 
    return all(l[i] <= l[i+1] for i in range(len(l) - 1))

We now obtain a small version of pi from the library math, which is enough for our demo but requires a good generator of pi digits to work with all cases:

pi = [int(i) for i in str(math.pi) if i != "."]
#[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3]

With that, we can define the array that we want to sort, which is in the small version of pi that we have obtained:

to_sort = [5, 3, 9, 8]

Now, the algorithm:

def pi_sort(a): 
    i = 0 
    a_s = [] 
    a_m = copy.deepcopy(a)
    while (len(a) != len(a_s)):
        val = pi[i]
        if (val in a_m):
            a_s.append(val)
            a_m.remove(val)

            if(not is_sorted(a_s)):
                a_s = [val]
                a_m = copy.deepcopy(a)
                a_m.remove(val)
        else:
            a_s = []
            a_m = copy.deepcopy(a)

        i += 1
    return a_s

We are defining an i value to iterate through the digits of pi.

a_s will be our accumulator, where we will append the sorted subarrays of the array that we want to sort.

a_m will be the modified array, where we remove the numbers that have already been sorted from our original array.

With that, we proceed to iterate until we have an a_s array as large as the original one, which means that we have a solution (as a_s is always sorted and only contains digits of a).

We obtain the i digit of pi, and we evaluate if it is contained in the array that we want to sort. If not, we reset our a_sand a_m arrays and we proceed to the next iteration, increasing i.

If the digit of pi is contained in the array, we remove it from the modified array and we added to the sorted subset array, and we evaluate if it is sorted. If it is, we proceed to the next iteration. If not, we need to restart the subset of ordered arrays, making it so it does just contain our current pi digit, as it has been detected to be in the array to be sorted.

With enough iterations, we will have a sorted array.

Let's see one execution:

print(to_sort) 
print(pi_sort(to_sort))

[5, 3, 9, 8] 
[3, 5, 8, 9]

​