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:
Today 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:
Sunday at 12:41 PM
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: 24129025" data-attributes="member: 470863"><p><span style="font-size: 15px"><span style="color: blue">Elakiri...enam den code eka weda karanna one pothe widihata...meka run karala balanna machan...</span></span></p><p></p><p><span style="font-size: 12px">#include<Stepper.h></span></p><p><span style="font-size: 12px">const int ForwardLimitSwitchPin = 2; //pins for two LS</span></p><p><span style="font-size: 12px">const int ReverseLimitSwitchPin = 7;</span></p><p><span style="font-size: 12px">const int StepperStepPin = 4; //pins for Stepper control</span></p><p><span style="font-size: 12px">const int StepperDirectionPin = 5;</span></p><p><span style="font-size: 12px">const int buttonPin = 6; //pin for the Pushbutton </span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">const int StepperMaxRPM = 100;</span></p><p><span style="font-size: 12px">bool ispushbuttonpressed = false; //boolean to store push button logic (used to build the logics)</span></p><p><span style="font-size: 12px">int buttonState = 0; //state of the push button</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">Stepper stepper(200, StepperStepPin, StepperDirectionPin); //initialize stepper</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">pinMode(buttonPin, INPUT_PULLUP); //declare push button signal as an input</span></p><p><span style="font-size: 12px">stepper.setSpeed(StepperMaxRPM); </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); //update push button state</span></p><p><span style="font-size: 12px">if (buttonState == 0) { //push button is pressed</span></p><p><span style="font-size: 12px">ispushbuttonpressed = true;</span></p><p><span style="font-size: 12px">} else {</span></p><p><span style="font-size: 12px">ispushbuttonpressed = false;</span></p><p><span style="font-size: 12px">}</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">// Run if push button is pressed && LS1 is not pressed - LOOP 1</span></p><p><span style="font-size: 12px">if ((ispushbuttonpressed == true) && (digitalRead(ForwardLimitSwitchPin) != 0)) { </span></p><p><span style="font-size: 12px">while (digitalRead(ForwardLimitSwitchPin) != 0) {</span></p><p><span style="font-size: 12px">stepper.step(1); //stepper steps forward </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">// Run if push button is pressed && LS2 is not pressed - LOOP 2</span></p><p><span style="font-size: 12px">else if ((ispushbuttonpressed == true) && (digitalRead(ReverseLimitSwitchPin) != 0)) { </span></p><p><span style="font-size: 12px">while (digitalRead(ReverseLimitSwitchPin) != 0) {</span></p><p><span style="font-size: 12px">stepper.step(-1); //stepper steps reverse </span></p><p><span style="font-size: 12px">}</span></p><p><span style="font-size: 12px">ispushbuttonpressed == false; //re-set to avoid motor turning forward once reached S1 </span></p><p><span style="font-size: 12px">} </span></p><p><span style="font-size: 12px">} </span></p></blockquote><p></p>
[QUOTE="apikaluda?, post: 24129025, member: 470863"] [SIZE=4][COLOR=blue]Elakiri...enam den code eka weda karanna one pothe widihata...meka run karala balanna machan...[/COLOR][/SIZE] [SIZE=3]#include<Stepper.h> const int ForwardLimitSwitchPin = 2; //pins for two LS const int ReverseLimitSwitchPin = 7; const int StepperStepPin = 4; //pins for Stepper control const int StepperDirectionPin = 5; const int buttonPin = 6; //pin for the Pushbutton const int StepperMaxRPM = 100;[/SIZE] [SIZE=3]bool ispushbuttonpressed = false; //boolean to store push button logic (used to build the logics) int buttonState = 0; //state of the push button int codeSection = 0; //use to check code only (remove it once code is finalized!) Stepper stepper(200, StepperStepPin, StepperDirectionPin); //initialize stepper[/SIZE] [SIZE=3]void setup() { pinMode(ForwardLimitSwitchPin, INPUT_PULLUP); pinMode(ReverseLimitSwitchPin, INPUT_PULLUP); pinMode(buttonPin, INPUT_PULLUP); //declare push button signal as an input stepper.setSpeed(StepperMaxRPM); }[/SIZE] [SIZE=3]void loop() { buttonState = digitalRead(buttonPin); //update push button state if (buttonState == 0) { //push button is pressed ispushbuttonpressed = true; } else { ispushbuttonpressed = false; } // Run if push button is pressed && LS1 is not pressed - LOOP 1 if ((ispushbuttonpressed == true) && (digitalRead(ForwardLimitSwitchPin) != 0)) { while (digitalRead(ForwardLimitSwitchPin) != 0) { stepper.step(1); //stepper steps forward } ispushbuttonpressed == false; //re-set to avoid motor turning backward once reached S2 } // Run if push button is pressed && LS2 is not pressed - LOOP 2 else if ((ispushbuttonpressed == true) && (digitalRead(ReverseLimitSwitchPin) != 0)) { while (digitalRead(ReverseLimitSwitchPin) != 0) { stepper.step(-1); //stepper steps reverse } ispushbuttonpressed == false; //re-set to avoid motor turning forward once reached S1 } } [/SIZE] [/QUOTE]
Insert quotes…
Verification
Hath warak paha keeyada? (hatha wadikireema paha)
Post reply
Top
Bottom