You are on page 1of 3

// constants won't change.

They're used here to set pin numbers:


const int switchPin = 2; // the number of the Start Switch,
const int ledPin = 13; // the number of the LED pin for indicator

const int ledPin7 = 9; //representasi pin 7 pada CN39


const int ledPin11 = 8; //representasi pin 11 pada CN39
const int ledPin9 = 7; //representasi pin 9 pada CN39
const int ledPin5 = 6; //representasi pin 5 pada CN39

// variables will change:


int switchState = 0; // variable for reading the Start Switch status
int counter = 0;
int a=0;
int b=0;
int c=0;
int d=0;
int e=0;
int f=0;
int g=0;
int h=0;

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the Start Switch pin as an input:
pinMode(switchPin, INPUT);
}

void loop() {
// read the state of the Start Switch value:
switchState = digitalRead(switchPin);

//Program for virtual counter, if Hspeed or Lspeed fungtion HIGH, counter will
start counting

//if Hspeed is true, start counting. counter will increase 1 per 0.5 sec
if (ledPin7 == HIGH &&
ledPin11 == HIGH &&
ledPin9 == HIGH &&
ledPin5 == HIGH) {
counter=counter+1;
delay(500);
}
//if Lspeed is true start counting. counter will increase 1 per 1 sec.
else if (ledPin7 == HIGH &&
ledPin11 == HIGH &&
ledPin9 == HIGH &&
ledPin5 == HIGH) {
counter=counter+1;
delay(1000);
}

// Program 1. presser foot and needle will at Lowered state then


if (switchState == HIGH && counter ==0) {
// state 0 : presser foot & needle lowered
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin11, HIGH);
digitalWrite(ledPin9,HIGH);
digitalWrite(ledPin5,HIGH);
delay(500); //state 0 will remain for 0.5 sec
a=1; }
//sewing machine start with Hspeed
if (a==1 && counter <10){
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin11, HIGH);
digitalWrite(ledPin9,HIGH);
digitalWrite(ledPin5,HIGH);
}
if (counter==9){
b=1;
}
//state 1 : corner with radius, sewing machine at Lspeed
if (b==1 && counter <20){
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin11, HIGH);
digitalWrite(ledPin9,HIGH);
digitalWrite(ledPin5,HIGH);
}
if (counter==19){
c=1;
}
//state 2 : straight line , sewing machine at Hspeed
if (c==1 && counter <30){
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin11, HIGH);
digitalWrite(ledPin9,HIGH);
digitalWrite(ledPin5,HIGH);
}
if (counter==29){
d=1;
}
//state 3 : first 90 degree corner. presser foot up
if (d==1){
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin11, HIGH);
digitalWrite(ledPin9,HIGH);
digitalWrite(ledPin5,HIGH);
delay(500); //state 3 remain for 0.5 sec
e=1;
}
//state 4 : straight line, sewing machine at Hspeed
if (e==1 && counter <40){
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin11, HIGH);
digitalWrite(ledPin9,HIGH);
digitalWrite(ledPin5,HIGH);
}
if (counter==39){
f=1;
}
//state 5 : second 90 degree corner. presser foot up
if (f==1){
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin11, HIGH);
digitalWrite(ledPin9,HIGH);
digitalWrite(ledPin5,HIGH);
delay(500); //state 3 remain for 0.5 sec
g=1;
}
//state 6 : straight line, sewing machine at Hspeed
if (g==1 && counter <50){
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin11, HIGH);
digitalWrite(ledPin9,HIGH);
digitalWrite(ledPin5,HIGH);
}
if (counter==49) {
h=1;
}
//state 7 : thread trimmer
if (h==1){
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin11, HIGH);
digitalWrite(ledPin9,HIGH);
digitalWrite(ledPin5,HIGH);
}

You might also like