AutoHotkey | Android | Arduino | COMM140 | Fractals | Grammar Checkers | Knots | A Million Dots Activity | Processing | Processing for Scratch Users | Redbubble | Tutorials | Weather | World Time Meeting Planner | Favicon Generator.
Home > Tutorials > Arduino > Projects > Cotton Winder
I intend to build a cotton spool winder. The aim of the winder is to be able to wind cotton thread onto woodern spools neatly.
So far I have been testing the Adafruit Motorshield and a pair of NEMA17 Stepper Motors bounted at right angles.
I have test code for counting button presses for my first callabration button mounted on the Adafruit Motorshield
// Count and report the count of button presses on Digital Pin 2
// The serial Monitor displays the button Press count
// December 26, 2014
const int buttonPin = 2;
int buttonState = 0;
int oldState = 0;
int newState = 0;
int counter = 0;
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
newState = buttonState;
delay(20);
if(oldState == LOW){
if(newState == HIGH){
counter = counter +1;
Serial.println(counter);
}
// Serial.println("test");
}
oldState = buttonState;
}
I have added 2 additional pushbuttons on D10 & D12
// Incrienemts a postion counter with button press on D2
// Decremebts the pos counter with button press on D10
// Turns "on" / "off" with button press on D12
// December 26, 2014
int buttonStateUp = 0;
int buttonStateDown = 0;
int buttonStateStartStop = 0;
int newStateUp = 0;
int newStateDown = 0;
int newStateStartStop = 0;
int oldStateUp = 0;
int oldStateDown = 0;
int oldStateStartStop = 0;
int pos = 0;
int counterStartStop = 0;
boolean startStop = false;
void setup() {
Serial.begin(9600);
// Set all Pins as Outputs
for(int i=0; i<21; i++){
pinMode(i, OUTPUT);
}
// Set all outputs to LOW
for(int i=0; i<21; i++){
digitalWrite(i, LOW);
}
// Change pins 2, 10, & 12 to inputs
pinMode(2, INPUT);
pinMode(10, INPUT);
pinMode(12, INPUT);
}
void loop() {
buttonStateUp = digitalRead(2);
buttonStateDown = digitalRead(10);
buttonStateStartStop = digitalRead(12);
newStateUp = buttonStateUp;
newStateDown = buttonStateDown;
newStateStartStop = buttonStateStartStop;
delay(20); // used to debounce the button
if(oldStateUp == LOW){
if(newStateUp == HIGH){
pos = pos +1;
Serial.print("pos = ");
Serial.println(pos);
}
}
if(oldStateDown == LOW){
if(newStateDown == HIGH){
pos = pos -1;
Serial.print("pos = ");
Serial.println(pos);
}
}
if(oldStateStartStop == LOW){
if(newStateStartStop == HIGH){
startStop = !startStop;
if(startStop){
Serial.println("On");
}
else{
Serial.println("Off");
}
}
}
oldStateUp = newStateUp;
oldStateDown = newStateDown;
oldStateStartStop = newStateStartStop;
}
APA citation:
Russell, R. (2016, July 05, 07:25 am). Experiment: Determining the Acceleration Due to Gravity.
Retrieved November 24, 2024, from http://http://www.rupert.id.au/tutorials/arduino/projects/winder/index.php
Last refreshed: November 24 2024. 01:09.00 am
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.