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
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
Ad icon
Wechat qr verification
Pawan2005
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="apikaluda?" data-source="post: 24120487" data-attributes="member: 470863"><p><span style="font-size: 15px"><span style="color: Blue">Meka upload karala balanna machan...mokada wenne kiyanna</span></span></p><p></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 = 0; // 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> stepper.step(0); //STOP STEPPER AT BEGINNING (check this the correct way)?</p><p> buttonState = digitalRead(buttonPin); // read push button on-off</p><p> if (buttonState == 0) { //**LOW (not HIGH)</p><p> ispushbuttonpressed = true;</p><p> } else {</p><p> ispushbuttonpressed = false;</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> stepper.step(0); //STOP STEPPER (check this the correct way)?</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> stepper.step(0); //STOP STEPPER (check this the correct way)?</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: 24120487, member: 470863"] [SIZE=4][COLOR=Blue]Meka upload karala balanna machan...mokada wenne kiyanna[/COLOR][/SIZE] const int ForwardLimitSwitchPin = 2; const int ReverseLimitSwitchPin = 7; const int StepperStepPin = 4; const int StepperDirectionPin = 5; const int LimitSwitchActivated = 0; // 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() { stepper.step(0); //STOP STEPPER AT BEGINNING (check this the correct way)? buttonState = digitalRead(buttonPin); // read push button on-off if (buttonState == 0) { //**LOW (not HIGH) ispushbuttonpressed = true; } else { ispushbuttonpressed = false; } // 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 stepper.step(0); //STOP STEPPER (check this the correct way)? } // 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 stepper.step(0); //STOP STEPPER (check this the correct way)? } 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
Hathara warak wissa keeyada? (Hathara wadi karanna 20)
Post reply
Top
Bottom