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="apikaluda?" data-source="post: 24117420" data-attributes="member: 470863"><p><span style="color: Blue"><span style="font-size: 15px">Code eke Serial Monitoring wala logics wala awulak ahuwuna machan (motor eka run wena loops waladi variable states monitor wena eka atherila thibbe)...eka correct kala<img src="/styles/default/xenforo/smilies/default/rofl.gif" class="smilie" loading="lazy" alt=":rofl:" title="ROFL :rofl:" data-shortname=":rofl:" /> Ganan ganna epa...code eka run karanne nethuwane mama liyanne<img src="/styles/default/xenforo/smilies/default/rofl.gif" class="smilie" loading="lazy" alt=":rofl:" title="ROFL :rofl:" data-shortname=":rofl:" /></span></span></p><p><span style="color: Blue"><span style="font-size: 15px"></span></span></p><p></p><p></p><p><span style="font-size: 12px">const int ForwardLimitSwitchPin = 2;</span></p><p><span style="font-size: 12px">const int ReverseLimitSwitchPin = 3;</span></p><p><span style="font-size: 12px">const int StepperStepPin = 4;</span></p><p><span style="font-size: 12px">const int StepperDirectionPin = 5;</span></p><p><span style="font-size: 12px">const int LimitSwitchActivated = LOW; // Limit switch grounds pin</span></p><p><span style="font-size: 12px">const int StepperMaxRPM = 100;</span></p><p><span style="font-size: 12px">const int buttonPin = 6; // the number of the pushbutton pin (choose the correct pin here)</span></p><p><span style="font-size: 12px">bool ispushbuttonpressed = false; // Boolean to store push button logic </span></p><p><span style="font-size: 12px">int buttonState = 0; //**correction</span></p><p><span style="font-size: 12px">Stepper stepper(200, StepperStepPin, StepperDirectionPin);</span></p><p><span style="font-size: 12px">int codeSection = 0; //use to check code only (remove it once code is finalized!)</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">void setup() {</span></p><p><span style="font-size: 12px"> pinMode(ForwardLimitSwitchPin, INPUT_PULLUP);</span></p><p><span style="font-size: 12px"> pinMode(ReverseLimitSwitchPin, INPUT_PULLUP);</span></p><p><span style="font-size: 12px"> stepper.setSpeed(StepperMaxRPM);</span></p><p><span style="font-size: 12px"> pinMode(buttonPin, INPUT); //declare push button signal as an input</span></p><p><span style="font-size: 12px"> Serial.begin(9600); //Serial Monitoring ON</span></p><p><span style="font-size: 12px"> Serial.println("Push button state\t\tForward LS State\t\tReverse LS State\t\tCode Section");</span></p><p><span style="font-size: 12px">}</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">void loop() {</span></p><p><span style="font-size: 12px"> buttonState = digitalRead(buttonPin); // read push button on-off</span></p><p><span style="font-size: 12px"> if (buttonState == LOW) { //**LOW (not HIGH)</span></p><p><span style="font-size: 12px"> ispushbuttonpressed = true;</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> // Step forward until the limit switch is activated (forward rotating when hits S1) - LOOP 1</span></p><p><span style="font-size: 12px"> if ((ispushbuttonpressed == true) && (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated)) { //**corrections added</span></p><p><span style="font-size: 12px"> codeSection = 1;</span></p><p><span style="font-size: 12px"> while (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated) {</span></p><p><span style="font-size: 12px"> stepper.step(1);</span></p><p><span style="font-size: 12px"> Serial.print(buttonState);</span></p><p><span style="font-size: 12px"> Serial.print("\t\t\t");</span></p><p><span style="font-size: 12px"> Serial.print(digitalRead(ForwardLimitSwitchPin));</span></p><p><span style="font-size: 12px"> Serial.print("\t\t\t"); </span></p><p><span style="font-size: 12px"> Serial.print(digitalRead(ReverseLimitSwitchPin));</span></p><p><span style="font-size: 12px"> Serial.print("\t\t\t");</span></p><p><span style="font-size: 12px"> Serial.println(codeSection);</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> ispushbuttonpressed == false; //re-set to avoid motor turning backward once reached S2</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> </span></p><p><span style="font-size: 12px"> // Step reverse until the limit switch is activated (forward rotating when hits S2) - LOOP 2</span></p><p><span style="font-size: 12px"> else if ((ispushbuttonpressed == true) && (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated)) { //**corrections added</span></p><p><span style="font-size: 12px"> codeSection = 2;</span></p><p><span style="font-size: 12px"> while (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated) {</span></p><p><span style="font-size: 12px"> stepper.step(-1);</span></p><p><span style="font-size: 12px"> Serial.print(buttonState);</span></p><p><span style="font-size: 12px"> Serial.print("\t\t\t");</span></p><p><span style="font-size: 12px"> Serial.print(digitalRead(ForwardLimitSwitchPin));</span></p><p><span style="font-size: 12px"> Serial.print("\t\t\t"); </span></p><p><span style="font-size: 12px"> Serial.print(digitalRead(ReverseLimitSwitchPin));</span></p><p><span style="font-size: 12px"> Serial.print("\t\t\t");</span></p><p><span style="font-size: 12px"> Serial.println(codeSection);</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"> ispushbuttonpressed == false; //re-set to avoid motor turning backward once reached S1</span></p><p><span style="font-size: 12px"> }</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px"> Serial.print(buttonState);</span></p><p><span style="font-size: 12px"> Serial.print("\t\t\t");</span></p><p><span style="font-size: 12px"> Serial.print(digitalRead(ForwardLimitSwitchPin));</span></p><p><span style="font-size: 12px"> Serial.print("\t\t\t"); </span></p><p><span style="font-size: 12px"> Serial.print(digitalRead(ReverseLimitSwitchPin));</span></p><p><span style="font-size: 12px"> Serial.print("\t\t\t");</span></p><p><span style="font-size: 12px"> Serial.println(codeSection);</span></p><p><span style="font-size: 12px">} </span></p></blockquote><p></p>
[QUOTE="apikaluda?, post: 24117420, member: 470863"] [COLOR=Blue][SIZE=4]Code eke Serial Monitoring wala logics wala awulak ahuwuna machan (motor eka run wena loops waladi variable states monitor wena eka atherila thibbe)...eka correct kala:rofl: Ganan ganna epa...code eka run karanne nethuwane mama liyanne:rofl: [/SIZE][/COLOR] [SIZE=3]const int ForwardLimitSwitchPin = 2; const int ReverseLimitSwitchPin = 3; 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); 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); } [/SIZE] [/QUOTE]
Insert quotes…
Verification
Payakata winadi keeyak tibeda?
Post reply
Top
Bottom