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
Puffin Rock Characters Plush Toy Set
anil1961
Updated:
Yesterday at 3:51 PM
Toyota Vitz scp10 For Sale
Lakmal Bandara
Updated:
Wednesday at 10:50 AM
Kandy
Welcome all my all new pet shop Bark.lk
dilumrane
Updated:
Monday at 12:26 PM
Windows RDP Only Rs.500 a month
Blogerwiki
Updated:
Nov 1, 2026
Ad icon
V2ray VPN for Tunneling
hu KANNA
Updated:
Oct 22, 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="apikaluda?" data-source="post: 24120157" data-attributes="member: 470863"><p><span style="font-size: 15px"><span style="color: Blue">Machan Push button state reading wala awulak thibba<img src="/styles/default/xenforo/smilies/default/shocked.gif" class="smilie" loading="lazy" alt=":shocked:" title="Shocked :shocked:" data-shortname=":shocked:" /><img src="/styles/default/xenforo/smilies/default/shocked.gif" class="smilie" loading="lazy" alt=":shocked:" title="Shocked :shocked:" data-shortname=":shocked:" />eka heduwa....den meken balanna </span></span></p><p></p><p></p><p></p><p>const int ForwardLimitSwitchPin = 2;</p><p>const int ReverseLimitSwitchPin = 7; //**changed from 3->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 = 100;</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> buttonState = digitalRead(buttonPin); // read push button on-off</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> buttonState = digitalRead(buttonPin); // read push button on-off</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> buttonState = digitalRead(buttonPin); // read push button on-off</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></blockquote><p></p>
[QUOTE="apikaluda?, post: 24120157, member: 470863"] [SIZE=4][COLOR=Blue]Machan Push button state reading wala awulak thibba:shocked::shocked:eka heduwa....den meken balanna [/COLOR][/SIZE] const int ForwardLimitSwitchPin = 2; const int ReverseLimitSwitchPin = 7; //**changed from 3->7 const int StepperStepPin = 4; const int StepperDirectionPin = 5; const int LimitSwitchActivated = LOW; // Limit switch grounds pin const int StepperMaxRPM = 100; 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); buttonState = digitalRead(buttonPin); // read push button on-off 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); buttonState = digitalRead(buttonPin); // read push button on-off 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 } buttonState = digitalRead(buttonPin); // read push button on-off 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); } [/QUOTE]
Insert quotes…
Verification
Hath warak paha keeyada? (hatha wadikireema paha)
Post reply
Top
Bottom