[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 580: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 636: sizeof(): Parameter must be an array or an object that implements Countable
Brads Electronic Projects Forum • Logic Gate Simulator Arduino and LCD - Page 2
Page 2 of 2

Re: Logic Gate Simulator Arduino and LCD

Posted: Tue Sep 25, 2012 11:38 pm
by Saimaster13
Well, I was trying to do something like this, but it does not set the variable "out" to anything (this code does not work):

Code: Select all

int out;
int in1;
int in2;

void setup(){}
void loop(){
AND(in1, in2, out);
}

void AND(int ANDin1, int ANDin2, int ANDout){
  if(ANDin1==1 && ANDin2==1){
    ANDout=1;
  }
  else{
  ANDout=0;
  }
}
I set the normal output to the AND output, then set the ANDoutput to on or off, but this does NOT set the normal output or change it in anyway. So, I'm going to have do this:

Code: Select all

int out;
int in1;
int in2;

void setup(){}
void loop(){
AND(in1, in2);
}

void AND(int ANDin1, int ANDin2){
  if(ANDin1==1 && ANDin2==1){
    out=1;
  }
  else{
  out=0;
  }
}


It'll make the code a little bigger when dealing with multiple outputs in multiple functions, but hopefully I can condense it enough.
Do you know of a better way to make the code?

Re: Logic Gate Simulator Arduino and LCD

Posted: Wed Sep 26, 2012 1:16 pm
by Saimaster13
Progress report, red is yet to be completed, yellow is a work in progress, green is completed:



Mode Select Screen

Port the basic logic simulator to this code

Number of logic gates select screen for complex simulation

Logic gate setup screen

complex simulation screen

fixing the code so the button "noise" doesn't go through multiple screens when a button is pressed once

testing to see if the code actually works

voltage dividing buttons

code for voltage dividing buttons

Re: Logic Gate Simulator Arduino and LCD

Posted: Wed Sep 26, 2012 10:11 pm
by brad
Hmm, not having done a whole heap with arduino's language, are you sure that's how you setup a return value? I.E.

Code: Select all

void AND(int ANDin1, int ANDin2, int ANDout)
To me it just looks like you are declaring an integer ANDout, then in your routine you are assigning it either with a 1 or 0, but I don't see how this is then passed back to the instruction that called it.

I might have to have a read through the arduino cheat sheet to get some more info.

Re: Logic Gate Simulator Arduino and LCD

Posted: Thu Sep 27, 2012 12:57 am
by Saimaster13
Well that does not work. I wanted to make a simple way of changing the inputs and outputs of a logic function when running it in the code. I tried something like this (which does not work):

Code: Select all

AND(in1, in2, out); //what I run in the loop, it sets the AND function's ANDin1 to in1, ANDin2 to in2, and ANDout to out


void AND(int ANDin1, int ANDin2, int ANDout) //the function where the ints in the () are set to something else when the function is run

So what happens is, when in1 is HIGH or LOW, the AND function's ANDin1 is HIGH or LOW, same with in2 and ANDin2.
The problem is, I set the variable "out" as the ANDout value then had it write the ANDout value as either HIGH or LOW
. This does not transfer over to the out value.

So what I would have to do is define AND like this:

Code: Select all

void AND(int ANDin1, int ANDin2
Then I would have to manually put in the "out" variable in the code so that it would set it as either HIGH or LOW, I cannot change the ANDout to any variable I want. I would have to have a set variable (like "out"), which I could define as another variable in the main code, but it would be simpler if I did not have to do that.

Is it possible to do that? Allow a function to write to a variable by representing it as another variable?

(like when I write ANDout as HIGH, var1 is HIGH, and the variable can be changed for each time the function is run)

After writing all this, this is seeming more and more impossible, complicated, and unneeded, so if you have no idea if this is possible, how to do this, or whatever the heck I am saying, it doesn't really matter. I have found another way, and it is only a little bit more tedious to set up than this.

Re: Logic Gate Simulator Arduino and LCD

Posted: Thu Sep 27, 2012 4:32 am
by bitfogav
You can use a function like this, this will return either 1 or 0 and store the return value in the Global variable "MyAND".

Code: Select all

int out;
int in1;
int in2;
int MyAND;

void setup()
{
}

void loop()
{
 MyAND = AND(in1, in2);
}

int AND(int _in1, int _in2)
{
  if (_in1 ==1 && _in2==1){
     return 1;	
   else{
    return 0;
   }	
}

Re: Logic Gate Simulator Arduino and LCD

Posted: Thu Sep 27, 2012 5:07 am
by Saimaster13
That's exactly what I needed! Thanks!

Re: Logic Gate Simulator Arduino and LCD

Posted: Thu Sep 27, 2012 9:32 pm
by brad
You are the man bitfogav!