Post here to discuss all things Arduino!
Moderators: Chuckt, Garth, bitfogav
-
Saimaster13
- I practically live here!
- Posts: 176
- Joined: Mon Aug 13, 2012 4:23 am
- Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Post
by Saimaster13 » Tue Sep 25, 2012 11:38 pm
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?
Last edited by
Saimaster13 on Thu Sep 27, 2012 12:42 am, edited 2 times in total.
Joshua
-
Saimaster13
- I practically live here!
- Posts: 176
- Joined: Mon Aug 13, 2012 4:23 am
- Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Post
by Saimaster13 » Wed Sep 26, 2012 1:16 pm
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
Joshua
-
brad
- Site Admin
- Posts: 2578
- Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Post
by brad » Wed Sep 26, 2012 10:11 pm
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.
-
Saimaster13
- I practically live here!
- Posts: 176
- Joined: Mon Aug 13, 2012 4:23 am
- Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Post
by Saimaster13 » Thu Sep 27, 2012 12:57 am
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:
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.
Joshua
-
bitfogav
- Moderator
- Posts: 915
- Joined: Sun Mar 28, 2010 9:03 pm
- Location: United Kingdom
-
Contact:
Post
by bitfogav » Thu Sep 27, 2012 4:32 am
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;
}
}
If you don't know what Voltage your country is using, you shouldn't be doing electronics
-
Saimaster13
- I practically live here!
- Posts: 176
- Joined: Mon Aug 13, 2012 4:23 am
- Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Post
by Saimaster13 » Thu Sep 27, 2012 5:07 am
That's exactly what I needed! Thanks!
Joshua
-
brad
- Site Admin
- Posts: 2578
- Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Post
by brad » Thu Sep 27, 2012 9:32 pm
You are the man bitfogav!
Post Reply
[phpBB Debug] PHP Warning: in file
[ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line
1266:
count(): Parameter must be an array or an object that implements Countable
Who is online
Users browsing this forum: No registered users and 9 guests