comp-sci
Discord ID: 423219052849397773
17,577 total messages. Viewing 100 per page.
Prev |
Page 18/176
| Next
>postfix
<:super_edgy:426099058466095119>
They do it the first way to try to avoid something like this:
```c
if (x = 3) { ... }```
when you actually meant
```c
if (x == 3) { ... }```
But every compiler and LINT tool catches that and warns about it.
In GCC, for instance, you'd have to write
```c
if ((x = 3)) { ... }```
to make the compiler like that. One legitimate use case of that would be
```cpp
int n;
if ((n = scanf(...)) != EOF) {
// now use n
switch (n) {
case 0:
return -1;
case 1:
// ...
...
} else {
// handle the case where scanf returned EOF
}
```
Peak wokeness: Translating Java into assembly code
Kill Me, I've accepted that I'm not getting either %x or %d done
you don't need to print everything lol
kys
Lol
wtf
is that real?
no lol
too bad I'll never use it
learning about reverse engineering is so much fun
do you guys do much of it?
I need to practice reading assembly code
no
Yus
Nothing unusual there.
It's supposed to be like that.
floating point arithmetic is <:LITAF:252198535426998272>
Itโs ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ๐ฅ
I finally have the portrait monitor I've always wanted
I should get another one when I can.
It's vesa-mounted to rotate.
@Deleted User Just finished my last lab for that assembly class, was all in C though, working with the GPIO on the Raspberry Pi and five pushbuttons to light up ad RGB LED and increase and decrease brightness.
Although I'm now seeing dots everywhere from the LED constantly flashing in my face.
@meratrix nice
Inspired by your ARM antics, I'm too writing code for some shitty hardware.
lmao
Coding on the Wii U.
lol
At least it's mostly C++.
I actually had a problem with this GPIO lab, but then realized I had wired all my pushbuttons as active high.
๐คฆ -> ME
And to balance out the high level, I spent last night designing a simple circuit for my parents.
nice
I think my summer project is gonna be a multiplayer text based RPG
Good old NE555 and the "you may need a capacitor here, gotta try it out and see what happens" instructions.
lol
Good get
@DanielKO what is the Wii U like to program? is it annoying or moderate?
Libraries and shit is a bit fragmented, everyone has their own BSD sockets header, each slightly broken.
And you can't use `cout`, only `printf`, or the entire system crashes.
And of course, with regards to the system functions, there's no documentation.
sounds ez <:Kappa:260415088702390273>
good luck with that
Sounds fun
For those that missed it.
TL;DR: if you have a custom system, register your device to not get locked out of some restricted apps (like Netflix.)
```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <wiringPi.h>
#include <softPwm.h>
#define RI 29
#define BI 28
#define GI 27
#define RO 23
#define BO 22
#define GO 21
#define HIGHER 1
#define LOWER 0
// DEBUGGING PRINTF STATEMENTS
void debugPrint(int rValue, int bValue, int gValue, int hValue, int lValue, int i, int j, int k, int rBright, int bBright, int gBright, float total_t) {
printf("DEBUG PRINTF\n");
printf("rValue:\t%d\n", rValue);
printf("bValue:\t%d\n", bValue);
printf("gValue:\t%d\n", gValue);
printf("hValue:\t%d\n", hValue);
printf("lValue:\t%d\n", lValue);
printf("i:\t%d\n", i);
printf("j:\t%d\n", j);
printf("k:\t%d\n", k);
printf("rBright:\t%d\n", rBright);
printf("bBright:\t%d\n", bBright);
printf("gBright:\t%d\n", gBright);
printf("running time:\t%f\n", total_t);
printf("\n");
delay(1000);
}
// INITIALIZATION OF RED, GREEN, AND BLUE OUTPUT GPIO PINS
void initializeLED(void) {
softPwmCreate(RO, 0, 100);
softPwmCreate(BO, 0, 100);
softPwmCreate(GO, 0, 100);
}
```
```c
int main(void) {
clock_t start, end; // FOR DEBUGGING
start = clock();
printf("Raspberry Pi PWM\n\n");
if (wiringPiSetup() == -1) {
return 1;
}
// SET PIN MODES
pinMode(RI, INPUT);
pinMode(BI, INPUT);
pinMode(GI, INPUT);
pinMode(HIGHER, INPUT);
pinMode(LOWER, INPUT);
// INITIALIZE GPIO VALUES
int rValue = 0;
int bValue = 0;
int gValue = 0;
int hValue = 0;
int lValue = 0;
// INITIALIZE BRIGHTNESS VALUES
int i = 100;
int j = 100;
int k = 100;
// INITIALIZE OUTPUT OUTPUT GPIO
initializeLED();
while (1) {
// READ FROM PUSHBUTTONS
rValue = digitalRead(RI);
bValue = digitalRead(BI);
gValue = digitalRead(GI);
hValue = digitalRead(HIGHER);
lValue = digitalRead(LOWER);
delay(10);
```
```c
// CHECK IF RED BUTTON IS PRESSED
if (rValue == HIGH) {
if (hValue == HIGH) { // IS INCREASE BRIGHTNESS BUTTON PRESSED
i -= 5;
} else if (lValue == HIGH) { // IS DECREASE BRIGHTNESS BUTTON PRESSED
i += 5;
}
if (i > 100) { // IS BRIGHTNESS AT MAXIMUM OR MINIMUM
i = 100;
} else if (i < 0) {
i = 0;
}
softPwmWrite(RO, 100-i); // WRITE GPIO WITH NEW BRIGHTNESS
delay(100);
}
//CHECK IF BLUE BUTTON IS PRESSED
if (bValue == HIGH) {
if (hValue == HIGH) { // IS INCREASE BRIGHTNESS BUTTON PRESSED
j -= 5;
} else if (lValue == HIGH) { // IS DECREASE BRIGHTNESS BUTTON PRESSED
j += 5;
}
if (j > 100) { // IS BRIGHTNESS AT MAXIMUM OR MINIMUM
j = 100;
} else if (j < 0) {
j = 0;
}
softPwmWrite(BO, 100-j); // WRITE GPIO PIN WITH NEW BRIGHTNESS
delay(100);
}
// CHECK IF GREEN BUTTON IS PRESSED
if (gValue == HIGH) {
if (hValue == HIGH) { // IS INCREASE BRIGHTNESS BUTTON PRESSED
k -= 5;
} else if (lValue == HIGH) { // IS DECREASE BRIGHTNESS BUTTON PRESSED
k += 5;
}
if (k > 100) { // IS BRIGHTNESS AT MAXIMUM OR MINIMUM
k = 100;
} else if (k < 0) {
k = 0;
}
softPwmWrite(GO, 100-k); // WRITE GPIO PIN WITH NEW BRIGHTNESS
delay(100);
}
```
```c
// EVERYTHING BELOW IS JUST EXTRA ADDED FEATURES USING BUTTON COMBINATIONS
// CHECKS FOR RESET BUTTON COMBINATION
if (rValue == HIGH) {
delay(150);
if (hValue == HIGH) {
delay(150);
if (lValue == HIGH) {
printf("BUTTON COMBINATION 1\n");
printf("RESETING LED\n\n");
i = 100;
j = 100;
k = 100;
softPwmWrite(RO, 0);
softPwmWrite(BO, 0);
softPwmWrite(GO, 0);
delay(2000);
softPwmWrite(RO, 100);
delay(250);
softPwmWrite(RO, 0);
softPwmWrite(BO, 100);
delay(250);
softPwmWrite(BO, 0);
softPwmWrite(GO, 100);
delay(250);
softPwmWrite(GO, 0);
delay(250);
}
}
```
```c
// CHECKS FOR EXIT BUTTON COMBINATION
} else if (bValue == HIGH) {
delay(150);
if (hValue == HIGH) {
delay(150);
if (lValue == HIGH) {
printf("BUTTON COMBINATION 2\n");
printf("EXITING PROGRAM\n\n");
softPwmWrite(RO, 0);
softPwmWrite(BO, 0);
softPwmWrite(GO, 0);
delay(2000);
softPwmWrite(RO, 100);
delay(250);
softPwmWrite(RO, 0);
softPwmWrite(BO, 100);
delay(250);
softPwmWrite(BO, 0);
softPwmWrite(GO, 100);
delay(250);
softPwmWrite(GO, 0);
delay(250);
exit(0);
}
}
```
```c
// CHECKS FOR RESET AND EXPERIMENTAL LIGHT SHOW COMBINATION
} else if (gValue == HIGH) {
delay(150);
if (hValue == HIGH) {
delay(150);
if (lValue == HIGH) {
printf("BUTTON COMBINATION 3\n");
printf("RESETING LED\n");
printf("RUNNING EXPERIMENTAL LIGHSTSHOW\n\n");
softPwmWrite(RO, 0);
softPwmWrite(BO, 0);
softPwmWrite(GO, 0);
delay(2000);
```
```c
while (1) {
softPwmWrite(RO, 100);
delay(1000);
softPwmWrite(RO, 0);
softPwmWrite(GO, 50);
delay(1000);
softPwmWrite(RO, 75);
softPwmWrite(BO, 100);
softPwmWrite(GO, 0);
delay(1000);
softPwmWrite(GO, 100);
softPwmWrite(RO, 10);
softPwmWrite(BO, 0);
delay(1000);
delay(2000);
softPwmWrite(RO, 0);
softPwmWrite(BO, 0);
softPwmWrite(GO, 0);
hValue = digitalRead(HIGHER);
lValue = digitalRead(LOWER);
if (hValue == HIGH && lValue == HIGH) {
printf("ENDING EXPERIMENTAL LIGHTSHOW\n");
printf("RESETING LED\n\n");
softPwmWrite(RO, 0);
softPwmWrite(BO, 0);
softPwmWrite(GO, 0);
delay(3000);
break;
}
}
softPwmWrite(RO, 100);
delay(250);
softPwmWrite(RO, 0);
softPwmWrite(BO, 100);
delay(250);
softPwmWrite(BO, 0);
softPwmWrite(GO, 100);
delay(250);
softPwmWrite(GO, 0);
}
}
}
end = clock();
// uncomment the below line to debugg
// debugPrint(rValue, bValue, gValue, hValue, lValue, i, j, k, 100-i, 100-j, 100-k, end-start);
}
return 0;
}
```
@Deleted User This is all the code for the GPIO RGB LED color mixer
wtf
>debugPrintf()
mfw
Don't judge my methods.
๐
`int rValue, int bValue, int gValue, int hValue, int lValue, int i, int j, int k, int rBright, int bBright, int gBright, float total_t`
holy moly
that is a lot of parameters
isn't it better to just put them in scope instead of passing them as parameters
or use pointers or something idk
I wanted to be able to easily comment out all debugging when I don't need to do it. But I still wanted it to be there because the TA's want to see the steps we took to complete the lab.
I'd make a `Buttons` struct to hold them all.
I get anxious when there's a bunch of variables that can end up part of a copy-paste accident.
๐คฃ
@Deleted User One thing I did not miss about Java was Null Pointer Exceptions, ben trying to finish an old project I started during winter break last year.
Even better are the MethodNotFound exceptions.
I think you mean nUlL pOiNtEr ExCeP
๐คฃ
what's the best sort of loop?
The one that violates scopes.
Duff's Device.
```c
void send(short *to, short *from, int count)
{
int n = (count + 7) / 8;
switch (count % 8) {
case 0: do { *to = *from++;
case 7: *to = *from++;
case 6: *to = *from++;
case 5: *to = *from++;
case 4: *to = *from++;
case 3: *to = *from++;
case 2: *to = *from++;
case 1: *to = *from++;
} while (--n > 0);
}
}
```
Followed by the `for-ever` loop:
```c
for (;;) {
/* ... */
}```
https://i.redd.it/ososfbmrcat01.png
Need to refurbish my old laptop to a Linux box sometime
@Legiondude eh arch
you must have alot of free time
I do, but the screenshot isn't mine
Looks nice tho
oh nvm then
That's the desktop environment not arch that makes it look nice
You could intall that DE on any Linux distro
17,577 total messages. Viewing 100 per page.
Prev |
Page 18/176
| Next