Pages: [1] 2   Go Down
Author Topic: How to Create logic  (Read 909 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Edison Member
*
Karma: 49
Posts: 2191
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Quote
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.

Quote
Now I want to create logic, like if PIN** & PIN** high than PIN**  should HIGH
Read the reference section!.

Mark


Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1120
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Shannon Member
****
Karma: 222
Posts: 12518
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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,

Code:
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 Offline
Brattain Member
*****
Karma: 285
Posts: 25623
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Still it's not working
whatever that means.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

still This part is not working.

Quote
if i want off all LED at the same time when P1 and L2 both are HIGH(on).
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 285
Posts: 25623
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Where is your debug output?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also this part of our code is not working

Code:
if (L2State ==HIGH && P1State==HIGH)
 {
   digitalWrite(S1, LOW); 
    digitalWrite(S3, LOW);
   
 }

  }
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 285
Posts: 25623
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could plz tell me how to fix the floating outputs

This is the circuit we used with 4 O/P and I/P(repeated the same circuit 4 times)

http://www.seeedstudio.com/wiki/images/thumb/5/55/Arduino_Sidekick_Pushbutton_LED.jpg/400px-Arduino_Sidekick_Pushbutton_LED.jpg
Logged

SG
Offline Offline
Sr. Member
****
Karma: 11
Posts: 495
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1] 2   Go Up
Jump to: