Offline
Newbie
Karma: 0
Posts: 31
|
 |
« on: March 07, 2013, 10:25:34 pm » |
Hi, Now I am working on Logical project, Let me explain what I want to do, I have 4 inputs INPUT 1, INPUT 2, INPUT 3, INPUT 4 (I Don’t know where to give input/Which pin of arduino can use as input) Now I want output at PIN ** (I don’t know where to receive Output/which pin of arduino can use as output) I need output at output pin after some time like I want to add “Wait (1000)” like at every pin, Eg: if I am give input at pin **, receive output at pin** after some particular time. Now I want to create logic, like if PIN** & PIN** high than PIN** should HIGH Please guide me how to create this logic.
|
|
|
|
|
Logged
|
|
|
|
|
Poole, Dorset, UK
Offline
God Member
Karma: 8
Posts: 672
|
 |
« Reply #1 on: March 07, 2013, 10:46:41 pm » |
INPUT 1, INPUT 2, INPUT 3, INPUT 4 (I Don’t know where to give input/Which pin of arduino can use as input) Now I want output at PIN ** (I don’t know where to receive Output/which pin of arduino can use as output)
You can use any of the I/O pins as input or output, but stay away from pins 0 and 1 as they are used for serial comms. I need output at output pin after some time like I want to add “Wait (1000)” like at every pin,
"wait is called delay and you should never use it! - See the blink without delay example and FSM's (Finite State Machines) in the playground. Now I want to create logic, like if PIN** & PIN** high than PIN** should HIGH
Read the reference section!. Mark
|
|
|
|
|
Logged
|
|
|
|
|
Brisbane, Australia
Offline
God Member
Karma: 17
Posts: 812
|
 |
« Reply #2 on: March 08, 2013, 07:38:58 am » |
Read the reference section!.
Specifically look at the digitalRead() and digitalWrite() functions. If you're familiar with other microcontrollers this should get you on the way. As Mark mentioned above delay() might not be ideal for your project as it is a blocking function - your code will mostly not respond to external inputs while it is running. I wouldn't go so far as to say never use it, but it's rare that it's the best choice for anything more than the most simple cases. If you are completely unfamiliar with Arduino there are some excellent tutorials available not just here, but also on youtube. This series by Jeremy Blum is a good place to start imo. All the best, Geoff
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #3 on: May 05, 2013, 08:42:09 am » |
SO finally m with my logic... let me know if any one can help me to achieve req output....
i have 4 input
Consider input as push button and OUTPUT as LED
INPUT= P1 OUTPUT= S1 INPUT= p2 OUTPUT= S2 INPUT= L1 OUTPUT= S3 INPUT= L2 OUTPUT= S4
now see my logic req.
CASE 1 When P1 on S1 and S3 on for 10 sec but if
L2 on Close S1 and S3 and Open S2 and S4 for 10 swcond
IF L1 on Close S1,S2,S3,S4
CASE 2
when P2 on S3 on for 10 sec
but
if L2 on
close S3 Open S4 for 1o sec
If L1 on Close Close S1,S2,S3,S4
Consider OPEN as On and CLOSE as Off
please let me know if any one can solve this logic
|
|
|
|
« Last Edit: May 05, 2013, 08:45:08 am by chetan0412 »
|
Logged
|
|
|
|
|
UK
Offline
Tesla Member
Karma: 89
Posts: 6400
-
|
 |
« Reply #4 on: May 05, 2013, 09:00:12 am » |
CASE 1 When P1 on S1 and S3 on for 10 sec but if
L2 on Close S1 and S3 and Open S2 and S4 for 10 swcond
The sort of behaviour you're describing is certainly feasible and not difficult to code once you have got the hang of it. However, although your description is reasonably detailed it still has some ambiguity. For example, in the situation where P1 is on and L2 is also on, it's not clear which should take precedence with respect to the behaviour described above. Similarly for the other parts of the code where different input states affect the same outputs.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #5 on: May 05, 2013, 10:07:29 pm » |
hi PeterH,
currently we are working on hydraulic system which we want to control by arduino.
here P1 is piston and L2 is limit switch , which is at the bottom limit of the piston strock.
when p1 coming at down side it will Activate L2(push L2)
Means
CASE 1 When P1 on (Piston going down side, Piston supply connected to P1) S1 and S3 on for 10 sec (Same time S1 and S3 pin should be high) but if
L2 on Close S1 and S3 and Open S2 and S4 for 10 second (means when piston push L2 limit switch after reaching/triggering L2, S1 and S3 should be Low and S2 and S4 High for 10 sec)
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #6 on: May 06, 2013, 06:26:49 am » |
Hi to all, Just i tried to complete some part, but i am stuck at some place , let me know if anyone can solve this problem. In this program if i want off all LED at the same time when P1 and L2 both are HIGH(on). I've tried to use boolean AND operator,if, do while, while Still it's not working ..Let me know if there is any logical error my code is, const int P1 = 2; // the number of the pushbutton pin const int P2 = 3; // the number of the pushbutton pin const int L1 = 4; // the number of the pushbutton pin const int L2 = 5; // the number of the pushbutton pin
int S1 = 8; // the number of the LED pin int S2 = 9; // the number of the LED pin int S3 = 10; // the number of the LED pin int S4 = 11; // the number of the LED pin
// variables will change: int P1State = 0; // variable for reading the pushbutton status int P2State = 0; // variable for reading the pushbutton status int L1State = 0; // variable for reading the pushbutton status int L2State = 0; // variable for reading the pushbutton status
void setup() { // initialize the LED pin as an output: pinMode(S1, OUTPUT); pinMode(S2, OUTPUT); pinMode(S3, OUTPUT); pinMode(S4, OUTPUT); // initialize the pushbutton pin as an input: pinMode(P1, INPUT); pinMode(P2, INPUT); pinMode(L1, INPUT); pinMode(L2, INPUT); }
void loop(){
// FOR P1 ACTIVE P1State = digitalRead(P1); P2State = digitalRead(P2); L1State = digitalRead(L1); L2State = digitalRead(L2);
if (P1State == HIGH) { // turn LED on: digitalWrite(S1, HIGH); digitalWrite(S3, HIGH); digitalWrite(S2, LOW); digitalWrite(S4, LOW); } if (L2State == HIGH) { digitalWrite(S1, LOW); digitalWrite(S3, LOW); digitalWrite(S2, HIGH); digitalWrite(S4, HIGH); } if (L1State ==HIGH) { digitalWrite(S1, LOW); digitalWrite(S3, LOW); digitalWrite(S2, LOW); digitalWrite(S4, LOW); } if (L2State ==HIGH && P1State==HIGH) { digitalWrite(S1, LOW); digitalWrite(S3, LOW); }
}
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #7 on: May 06, 2013, 06:29:46 am » |
Still it's not working whatever that means.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #8 on: May 06, 2013, 06:31:18 am » |
still This part is not working. if i want off all LED at the same time when P1 and L2 both are HIGH(on).
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #9 on: May 06, 2013, 06:33:00 am » |
Where is your debug output?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #10 on: May 06, 2013, 06:36:48 am » |
when we press L2 and P1 all the LED glow i.e all O/P are high at same time where as they should have been low.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #11 on: May 06, 2013, 06:45:11 am » |
Also this part of our code is not working if (L2State ==HIGH && P1State==HIGH) { digitalWrite(S1, LOW); digitalWrite(S3, LOW); }
}
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #12 on: May 06, 2013, 06:47:26 am » |
Also this part of our code is not working It is doing something, but you haven't said what. Slow down, post a schematic, show how you are preventing your inputs from floating. Bear in mind that what you observe may not be what is actually happening - the processor is very fast.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
|
|
SG
Offline
Sr. Member
Karma: 3
Posts: 268
Arduino rocks
|
 |
« Reply #14 on: May 06, 2013, 06:53:59 am » |
you need to debounces the input, without which pressing the button once would appear to the code as multiple presses. http://www.arduino.cc/en/Tutorial/Switch
|
|
|
|
|
Logged
|
|
|
|
|
|