Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Handmade Character Soft Toys
anil1961
Updated:
Today at 2:11 PM
Bodim.lk out now !
Manoj Suranga Bandara
Updated:
Sunday at 3:05 AM
Power Lifting Lever Belt
SkullVamp
Updated:
Jun 13, 2026
Ad icon
port.lk Domain for sale
Lankan-Tech
Updated:
Jun 13, 2026
Colombo
Kaduwela - Two Storey House for Sale
dilrasan
Updated:
Jun 11, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Help
Arduino help
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="dushan90" data-source="post: 24120073" data-attributes="member: 74595"><p>Code eka wenas kala machan mehema</p><p></p><p></p><p>[CODE]#include<Stepper.h></p><p></p><p>const int ForwardLimitSwitchPin = 2;</p><p>const int ReverseLimitSwitchPin = 7;</p><p>const int StepperStepPin = 4;</p><p>const int StepperDirectionPin = 5;</p><p>const int LimitSwitchActivated = LOW; // Limit switch grounds pin</p><p>const int StepperMaxRPM = 600;</p><p>const int buttonPin = 6; // the number of the pushbutton pin (choose the correct pin here)</p><p>bool ispushbuttonpressed = false; // Boolean to store push button logic</p><p>int buttonState = 0; //**correction</p><p>Stepper stepper(200, StepperStepPin, StepperDirectionPin);</p><p>int codeSection = 0; //use to check code only (remove it once code is finalized!)</p><p></p><p>void setup() {</p><p>pinMode(ForwardLimitSwitchPin, INPUT_PULLUP);</p><p>pinMode(ReverseLimitSwitchPin, INPUT_PULLUP);</p><p>stepper.setSpeed(StepperMaxRPM);</p><p>pinMode(buttonPin, INPUT); //declare push button signal as an input</p><p>Serial.begin(9600); //Serial Monitoring ON</p><p>Serial.println("Push button state\t\tForward LS State\t\tReverse LS State\t\tCode Section");</p><p>}</p><p></p><p>void loop() {</p><p>buttonState = digitalRead(buttonPin); // read push button on-off</p><p>if (buttonState == LOW) { //**LOW (not HIGH)</p><p>ispushbuttonpressed = true;</p><p>}</p><p>// Step forward until the limit switch is activated (forward rotating when hits S1) - LOOP 1</p><p>if ((ispushbuttonpressed == true) && (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated)) { //**corrections added</p><p>codeSection = 1;</p><p>while (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated) {</p><p>stepper.step(1);</p><p>Serial.print(buttonState);</p><p>Serial.print("\t\t\t");</p><p>Serial.print(digitalRead(ForwardLimitSwitchPin));</p><p>Serial.print("\t\t\t");</p><p>Serial.print(digitalRead(ReverseLimitSwitchPin));</p><p>Serial.print("\t\t\t");</p><p>Serial.println(codeSection);</p><p>}</p><p>ispushbuttonpressed == false; //re-set to avoid motor turning backward once reached S2</p><p>}</p><p></p><p>// Step reverse until the limit switch is activated (forward rotating when hits S2) - LOOP 2</p><p>else if ((ispushbuttonpressed == true) && (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated)) { //**corrections added</p><p>codeSection = 2;</p><p>while (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated) {</p><p>stepper.step(-1);</p><p>Serial.print(buttonState);</p><p>Serial.print("\t\t\t");</p><p>Serial.print(digitalRead(ForwardLimitSwitchPin));</p><p>Serial.print("\t\t\t");</p><p>Serial.print(digitalRead(ReverseLimitSwitchPin));</p><p>Serial.print("\t\t\t");</p><p>Serial.println(codeSection);</p><p>}</p><p>ispushbuttonpressed == false; //re-set to avoid motor turning backward once reached S1</p><p>}</p><p></p><p>Serial.print(buttonState);</p><p>Serial.print("\t\t\t");</p><p>Serial.print(digitalRead(ForwardLimitSwitchPin));</p><p>Serial.print("\t\t\t");</p><p>Serial.print(digitalRead(ReverseLimitSwitchPin));</p><p>Serial.print("\t\t\t");</p><p>Serial.println(codeSection);</p><p>}[/CODE]</p></blockquote><p></p>
[QUOTE="dushan90, post: 24120073, member: 74595"] Code eka wenas kala machan mehema [CODE]#include<Stepper.h> const int ForwardLimitSwitchPin = 2; const int ReverseLimitSwitchPin = 7; const int StepperStepPin = 4; const int StepperDirectionPin = 5; const int LimitSwitchActivated = LOW; // Limit switch grounds pin const int StepperMaxRPM = 600; const int buttonPin = 6; // the number of the pushbutton pin (choose the correct pin here) bool ispushbuttonpressed = false; // Boolean to store push button logic int buttonState = 0; //**correction Stepper stepper(200, StepperStepPin, StepperDirectionPin); int codeSection = 0; //use to check code only (remove it once code is finalized!) void setup() { pinMode(ForwardLimitSwitchPin, INPUT_PULLUP); pinMode(ReverseLimitSwitchPin, INPUT_PULLUP); stepper.setSpeed(StepperMaxRPM); pinMode(buttonPin, INPUT); //declare push button signal as an input Serial.begin(9600); //Serial Monitoring ON Serial.println("Push button state\t\tForward LS State\t\tReverse LS State\t\tCode Section"); } void loop() { buttonState = digitalRead(buttonPin); // read push button on-off if (buttonState == LOW) { //**LOW (not HIGH) ispushbuttonpressed = true; } // Step forward until the limit switch is activated (forward rotating when hits S1) - LOOP 1 if ((ispushbuttonpressed == true) && (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated)) { //**corrections added codeSection = 1; while (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated) { stepper.step(1); Serial.print(buttonState); Serial.print("\t\t\t"); Serial.print(digitalRead(ForwardLimitSwitchPin)); Serial.print("\t\t\t"); Serial.print(digitalRead(ReverseLimitSwitchPin)); Serial.print("\t\t\t"); Serial.println(codeSection); } ispushbuttonpressed == false; //re-set to avoid motor turning backward once reached S2 } // Step reverse until the limit switch is activated (forward rotating when hits S2) - LOOP 2 else if ((ispushbuttonpressed == true) && (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated)) { //**corrections added codeSection = 2; while (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated) { stepper.step(-1); Serial.print(buttonState); Serial.print("\t\t\t"); Serial.print(digitalRead(ForwardLimitSwitchPin)); Serial.print("\t\t\t"); Serial.print(digitalRead(ReverseLimitSwitchPin)); Serial.print("\t\t\t"); Serial.println(codeSection); } ispushbuttonpressed == false; //re-set to avoid motor turning backward once reached S1 } Serial.print(buttonState); Serial.print("\t\t\t"); Serial.print(digitalRead(ForwardLimitSwitchPin)); Serial.print("\t\t\t"); Serial.print(digitalRead(ReverseLimitSwitchPin)); Serial.print("\t\t\t"); Serial.println(codeSection); }[/CODE] [/QUOTE]
Insert quotes…
Verification
Hath warak paha keeyada? (hatha wadikireema paha)
Post reply
Top
Bottom