Home Discord Chat
Go Back   ChiefsPlanet > Nzoner's Game Room

Reply
 
Thread Tools Display Modes
Old 10-13-2021, 08:27 PM  
Monticore Monticore is offline
I love your mom
 
Join Date: Feb 2020
Location: Sturgeon Falls, Ontario
Casino cash: $3054957
Nerd homework

My son needs help with his homework and I know nothing about coding , he is trying to get a RGB strip to light up with increasing intensity as more pressure is applied to sensor while also randomizing a series of colors .(llike a light up shoe)

this is what he has which he knows is horribly wrong i am pretty sure this is C/C+, this is his hisrt ever coding class so his knowledge is fairly limited.
I also know it is in french but it might still make sense to some of you

int valeur1 = 0; //variable de type integer pour enregistrer analog A0
int valeur2 = 0; //variable de type integer pour enregistrer analog A0
int valeur3 = 0;
int valeur4 = 0;
int valeur5 = 0;

void setup() {

Serial.begin(9600); //commence le serial pour ecrire les données
pinMode(A0,INPUT_PULLUP); //prepare A0 pour le pressure sensor
pinMode(3,OUTPUT); //prepare pin 3 pour output de 5V
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
}

void loop() {

valeur1 = analogRead(A0);
delay(1000);
valeur2 = (200/valeur1);
valeur3 = (valeur2*valeur2);




valeur4 = random(255);
valeur5 = valeur4;

if (valeur4 > valeur5){
valeur5--;
analogWrite(3,valeur5);

}

if (valeur4 < valeur5){
valeur5++;
analogWrite(3,valeur5);

}

if (valeur4 == valeur5){

valeur5;
analogWrite(3,valeur5);

}







if (valeur4 > valeur5){
valeur5++;
analogWrite(5,valeur5);

}

if (valeur4 < valeur5){
valeur5--;
analogWrite(5,valeur5);

}

if (valeur4 == valeur5){

analogWrite(5,valeur5);

}








if (valeur4 > valeur1){
valeur5++;
analogWrite(6,valeur5);

}

if (valeur4 < valeur5){
valeur5--;
analogWrite(6,valeur5);

}

if (valeur4 == valeur5){

analogWrite(6,valeur5);

}

}

would appreciate any help or insults
Posts: 6,522
Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.
    Reply With Quote
Old 10-14-2021, 05:45 AM   #31
ptlyon ptlyon is online now
Bono & Grbac wasn't enough
 

Join Date: Oct 2000
Location: Sioux City, IA
Casino cash: $13383829
If you need a poll rigged, a mom to bang, or even code, your first stop shop is CP!
__________________
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Advertise here: $19.99 a month
Posts: 33,241
ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.
    Reply With Quote
Old 10-14-2021, 06:43 AM   #32
Monticore Monticore is offline
I love your mom
 

Join Date: Feb 2020
Location: Sturgeon Falls, Ontario
Casino cash: $3054957
Quote:
Originally Posted by ptlyon View Post
If you need a poll rigged, a mom to bang, or even code, your first stop shop is CP!
link to the moms to bang thread could not find it with search.
Posts: 6,522
Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.
    Reply With Quote
Old 10-14-2021, 06:56 AM   #33
ptlyon ptlyon is online now
Bono & Grbac wasn't enough
 

Join Date: Oct 2000
Location: Sioux City, IA
Casino cash: $13383829
Billay's is available anytime
__________________
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Advertise here: $19.99 a month
Posts: 33,241
ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.
    Reply With Quote
Old 10-14-2021, 07:04 AM   #34
Grim Grim is offline
Starter
 

Join Date: Aug 2012
Casino cash: $-160000
Do you have any specs on the RGB strip and how the host system is connected to it (what are the three output pins connected to on the RGB strip)?

Edit: I guess it doesn't really matter.

I'd start by just reading the analog input and putting that value on the three outputs and verify that he can see a color change based off the pressure input.
I think it's been said a few times in this thread already but he needs to break it down into smaller chunks.

Last edited by Grim; 10-14-2021 at 07:11 AM..
Posts: 715
Grim must have mowed badgirl's lawn.Grim must have mowed badgirl's lawn.Grim must have mowed badgirl's lawn.Grim must have mowed badgirl's lawn.Grim must have mowed badgirl's lawn.Grim must have mowed badgirl's lawn.Grim must have mowed badgirl's lawn.Grim must have mowed badgirl's lawn.Grim must have mowed badgirl's lawn.Grim must have mowed badgirl's lawn.Grim must have mowed badgirl's lawn.
    Reply With Quote
Old 10-14-2021, 07:29 AM   #35
phisherman phisherman is online now
King Sandbagger
 

Join Date: Feb 2003
Location: The Summit, MO
Casino cash: $1925484
Quote:
Originally Posted by stanleychief View Post
Very true for the real world. For Arduino sketches though, it's pretty simplified. OO design here would likely be overkill. For a sketch file, you essentially have two methods that execute: setup and loop.

In setup, you initialize your variables, pins, etc. In loop, you put in the code that will repeatedly execute in a loop.

Considering the stated objectives, I'd solve the problem in the loop code like so:

* Read the pressure sensor value and convert that to a decimal value between 0 and 1.
* Generate random values for red, green and blue LEDs and store those values into three variables.
* Multiply each of those three variables by the converted pressure sensor value.
* Write the three values to the RGB LED output pins.
Well explained with a great algorithm added! Rep!
Posts: 3,790
phisherman wants to die in a aids tree fire.phisherman wants to die in a aids tree fire.phisherman wants to die in a aids tree fire.phisherman wants to die in a aids tree fire.phisherman wants to die in a aids tree fire.phisherman wants to die in a aids tree fire.phisherman wants to die in a aids tree fire.phisherman wants to die in a aids tree fire.phisherman wants to die in a aids tree fire.phisherman wants to die in a aids tree fire.phisherman wants to die in a aids tree fire.
    Reply With Quote
Old 10-14-2021, 09:05 AM   #36
ReynardMuldrake ReynardMuldrake is offline
2 Legit 2 Colquitt
 
ReynardMuldrake's Avatar
 

Join Date: Sep 2010
Casino cash: $4695754
I'm not much into coding but the following doesn't make much sense.

Quote:
valeur4 = random(255);
valeur5 = valeur4;

if (valeur4 > valeur5){
valeur5--;
analogWrite(3,valeur5);
If the values are already equal, why does it have to compare them?
Posts: 4,681
ReynardMuldrake has enough rep power to blowy ou to bits.ReynardMuldrake has enough rep power to blowy ou to bits.ReynardMuldrake has enough rep power to blowy ou to bits.ReynardMuldrake has enough rep power to blowy ou to bits.ReynardMuldrake has enough rep power to blowy ou to bits.ReynardMuldrake has enough rep power to blowy ou to bits.ReynardMuldrake has enough rep power to blowy ou to bits.ReynardMuldrake has enough rep power to blowy ou to bits.ReynardMuldrake has enough rep power to blowy ou to bits.ReynardMuldrake has enough rep power to blowy ou to bits.ReynardMuldrake has enough rep power to blowy ou to bits.
    Reply With Quote
Old 10-14-2021, 09:09 AM   #37
kepp kepp is offline
MVP
 
kepp's Avatar
 

Join Date: Aug 2005
Casino cash: $5479212
Quote:
Originally Posted by Monticore View Post
Appreciate the help guys , not sure if he figured it out i went to bed but will let you know
I think the question is mostly answered in here already, but just an aside as to coding style...he needs to give useful names to his variables. Just saying x, y, z equals something makes it difficult to follow the logic, even in his own head.

Also (and I've never worked with this Arduino stuff), since he already is setting up the serial port for comms, will Serial.print work as someone suggested? Or will that output over the current serial port link?
Posts: 14,482
kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.
    Reply With Quote
Old 10-14-2021, 09:10 AM   #38
kepp kepp is offline
MVP
 
kepp's Avatar
 

Join Date: Aug 2005
Casino cash: $5479212
Quote:
Originally Posted by ReynardMuldrake View Post
I'm not much into coding but the following doesn't make much sense.



If the values are already equal, why does it have to compare them?
That's a logic error...unreachable code.
Posts: 14,482
kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.kepp threw an interception on a screen pass.
    Reply With Quote
Old 10-14-2021, 09:12 AM   #39
tooge tooge is offline
MVP
 
tooge's Avatar
 

Join Date: Feb 2007
Location: Liberty, MO
Casino cash: $4214112
Have him change to something other than coding. It looks like french
Posts: 14,885
tooge is obviously part of the inner Circle.tooge is obviously part of the inner Circle.tooge is obviously part of the inner Circle.tooge is obviously part of the inner Circle.tooge is obviously part of the inner Circle.tooge is obviously part of the inner Circle.tooge is obviously part of the inner Circle.tooge is obviously part of the inner Circle.tooge is obviously part of the inner Circle.tooge is obviously part of the inner Circle.tooge is obviously part of the inner Circle.
    Reply With Quote
Old 10-14-2021, 09:40 AM   #40
stanleychief stanleychief is offline
Veteran
 
stanleychief's Avatar
 

Join Date: Aug 2002
Location: Kansas City, MO
Casino cash: $5386254
Quote:
Originally Posted by kepp View Post
I think the question is mostly answered in here already, but just an aside as to coding style...he needs to give useful names to his variables. Just saying x, y, z equals something makes it difficult to follow the logic, even in his own head.

Also (and I've never worked with this Arduino stuff), since he already is setting up the serial port for comms, will Serial.print work as someone suggested? Or will that output over the current serial port link?
Yep, Serial.print should work as well. I recommended Serial.println, which simply tacks on a linefeed as a convenience.

When doing Arduino programming and debugging, the serial line is how you write and read data from the device as it is operating. In essence, your IDE compiles down the C++ sketch file into a binary, uploads that over the serial line to the Arduino device, and then resets it. The reset makes it execute your code. The serial connection remains open, and any messages from the Arduino are sent across.
Posts: 1,192
stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.
    Reply With Quote
Old 10-14-2021, 10:06 AM   #41
Monticore Monticore is offline
I love your mom
 

Join Date: Feb 2020
Location: Sturgeon Falls, Ontario
Casino cash: $3054957
Quote:
Originally Posted by kepp View Post
I think the question is mostly answered in here already, but just an aside as to coding style...he needs to give useful names to his variables. Just saying x, y, z equals something makes it difficult to follow the logic, even in his own head.

Also (and I've never worked with this Arduino stuff), since he already is setting up the serial port for comms, will Serial.print work as someone suggested? Or will that output over the current serial port link?
I have no idea what anybody is talking about lol but he was trying some of the stuff suggested , not sure where he is at with it , he is working on it at school .

Normally I would spend the next few months and hundreds of hours learning some coding to be able to help him out but I have absolutely no interest .
Posts: 6,522
Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.Monticore would the whole thing.
    Reply With Quote
Old 10-14-2021, 10:27 AM   #42
DCTwister DCTwister is offline
Starter
 

Join Date: Oct 2017
Casino cash: $7910400
I’m not a coder, (although I am an engineer by education) but I do know Arduino the company extremely well.

Where you want to go is the Arduino forum https://forum.arduino.cc/
There are 1M members and you are likely to find plenty of good ideas and assistance.
Posts: 411
DCTwister is not part of the Right 53.DCTwister is not part of the Right 53.DCTwister is not part of the Right 53.DCTwister is not part of the Right 53.DCTwister is not part of the Right 53.DCTwister is not part of the Right 53.DCTwister is not part of the Right 53.DCTwister is not part of the Right 53.DCTwister is not part of the Right 53.DCTwister is not part of the Right 53.DCTwister is not part of the Right 53.
    Reply With Quote
Old 10-14-2021, 10:50 AM   #43
Chazno Chazno is offline
Starter
 

Join Date: Nov 2004
Location: asdf
Casino cash: $4657963
This is a little difficult given the lack of context to the code. I'm assuming the outputs 3,5 & 6 are in relation to RGB color. If not disregard this message. I don't see how you would add intensity based on the pressure sensor unless it is saying pin 3 determines power. IF that is the case we want to tie that to valuer1 and I would have to have more info on how the colors are determined.

I rewrote the loop for what I think would give you a random changing light every second, but without more information on the board with regard to setting intensity, I can't help you there.

void loop() {

valeur1 = analogRead(A0);
delay(1000);
valeur2 = (200 / valeur1); //need context on what these are for
valeur3 = (valeur2 * valeur2); //need context on what these are for

valeur4 = random(255); // three random values. One for each RGB. If you use only one you will be limited to 255 colors.
valeur5 = random(255);
valeur6 = random(255);

analogWrite(3,valeur4);
analogWrite(5,valeur5);
analogWrite(6,valeur6);


}
Posts: 507
Chazno is not part of the Right 53.Chazno is not part of the Right 53.Chazno is not part of the Right 53.Chazno is not part of the Right 53.Chazno is not part of the Right 53.Chazno is not part of the Right 53.Chazno is not part of the Right 53.Chazno is not part of the Right 53.Chazno is not part of the Right 53.Chazno is not part of the Right 53.Chazno is not part of the Right 53.
    Reply With Quote
Old 10-14-2021, 10:52 AM   #44
ptlyon ptlyon is online now
Bono & Grbac wasn't enough
 

Join Date: Oct 2000
Location: Sioux City, IA
Casino cash: $13383829
This shit sure ain't assembler
__________________
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Advertise here: $19.99 a month
Posts: 33,241
ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.ptlyon is obviously part of the inner Circle.
    Reply With Quote
Old 10-14-2021, 11:14 AM   #45
stanleychief stanleychief is offline
Veteran
 
stanleychief's Avatar
 

Join Date: Aug 2002
Location: Kansas City, MO
Casino cash: $5386254
I just hope this kid renames the variables before turning in the code. If I were grading the assignment, I'd be raising an eyebrow if the variables were French.

I once worked on some client's code, which was apparently written by a guy named Eric. Every variable in his code was prefixed with 'eric'. So the SQL DB connection was 'ericDbConn', and the result set was 'ericDbResult', the datarow object was 'ericDbRow', etc.

I thought that was pretty damned hilarious!
Posts: 1,192
stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.stanleychief has just been standing around suckin' on a big ol' chili dog.
    Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump




All times are GMT -6. The time now is 08:24 AM.


This is a test for a client's site.
Fort Worth Texas Process Servers
Covering Arlington, Fort Worth, Grand Prairie and surrounding communities.
Tarrant County, Texas and Johnson County, Texas.
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2024, vBulletin Solutions, Inc.