--- /dev/null
+TODO
+push.sh
--- /dev/null
+// sketch 03_01_interrupts
+
+int ledPin = 13;
+
+void setup()
+{
+ pinMode(ledPin, OUTPUT);
+ attachInterrupt(0, eventoAttivo, RISING); // 0 e' l'interrupt numero 0
+ // connesso al PIN D2, l'interrupt 1 e' connesso al PIN D3
+ // eventoAttivo : nome della funzione da richiamare
+ // per un ISRs e' sempre VOID
+ // LOW | RISING | FALLIN | CHANGE | HIGH
+}
+
+void loop()
+{
+ // Varie altre cose che da cui non dipende la gestione dell'interrupt
+ delay(5000);
+ digitalWrite(ledPin,LOW);
+}
+
+void eventoAttivo() // Sempre VOID
+{
+ digitalWrite(ledPin, HIGH);
+}
--- /dev/null
+/*
+ Blink with Narcoleptic
+
+ Normal Blink on a Uno uses 33.22 - 35.10ma
+ Narcoleptic version on a Uno uses 24.38 - 26.08ma
+
+ Normal Blink on a Nano uses 21.01 - 24.28ma
+ Narcoleptic version on a Nano uses 6.73 - 9.75ma
+
+ This should be way more efficient on a Arduino Mini
+ that has no USB chip - regulator. Arduino Mini should go from 17.2 to 3.2ma.
+
+ Turns on an LED on for one second, then off for one second, repeatedly.
+
+ This example code is in the public domain.
+ */
+
+// Pin 13 has an LED connected on most Arduino boards.
+// give it a name:
+int led = 13;
+#include <Narcoleptic.h>
+// the setup routine runs once when you press reset:
+void setup() {
+ // initialize the digital pin as an output.
+ pinMode(led, OUTPUT);
+}
+
+// the loop routine runs over and over again forever:
+void loop() {
+ digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
+ Narcoleptic.delay(1000); // wait for a second
+ digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
+ Narcoleptic.delay(1000); // wait for a second
+}
--- /dev/null
+/*
+ sprintf()
+
+ Uso di sprintf per formattare stringhe di testo
+ Nota: sprintf() non accetta floats
+
+ */
+int h = 12;
+int m = 3;
+int s = 2;
+
+void setup() {
+ // initialize serial communications at 9600 bps:
+ Serial.begin(9600);
+}
+
+void loop() {
+ char buffer[17]; // We need a buffer to hold the formatted ouput
+
+ sprintf(buffer, "Time: %2d:%02d:%02d", h, m, s); // C sintax
+
+ Serial.print(buffer);
+ Serial.flush();
+ exit(0);
+}
+
+
+++ /dev/null
-/*
- Blink v3
- Now with 2 variables and an extra LED (remember a ~320 ohms resistor).
- Turns on an LED on for one second, then off for one second, repeatedly.
-
- This example code is in the public domain.
- */
-
-// Pin 13 has an LED connected on most Arduino boards.
-// give it a name:
-int led = 13;
-int red = 12;
-int breve = 200;
-int lunga = 1000;
-
-// the setup routine runs once when you press reset:
-void setup() {
- // initialize the digital pin as an output.
- pinMode(led, OUTPUT);
- pinMode(red, OUTPUT);
-}
-
-// the loop routine runs over and over again forever:
-void loop() {
- digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(breve); // wait for a second
- digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
- delay(breve); // wait for a second
-
- digitalWrite(red, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(lunga); // wait for a second
- digitalWrite(red, LOW); // turn the LED off by making the voltage LOW
- delay(lunga);
-}
+++ /dev/null
-/*
- Blink v3
- Now with 2 variables and an extra LED (remember a ~320 ohms resistor).
- Turns on an LED on for one second, then off for one second, repeatedly.
-
- This example code is in the public domain.
- */
-
-// Pin 13 has an LED connected on most Arduino boards.
-// give it a name:
-int led = 13;
-int red = 12;
-int breve = 200;
-int lunga = 1000;
-
-// the setup routine runs once when you press reset:
-void setup() {
- // initialize the digital pin as an output.
- pinMode(led, OUTPUT);
- pinMode(red, OUTPUT);
-}
-
-// the loop routine runs over and over again forever:
-void loop() {
-lightRed();
-lightGreen();
-}
-
-void lightRed() {
- digitalWrite(red, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(lunga); // wait for a second
- digitalWrite(red, LOW); // turn the LED off by making the voltage LOW
- delay(lunga);
-}
-
-void lightGreen() {
- digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(breve); // wait for a second
- digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
- delay(breve); // wait for a second
-}
-
+++ /dev/null
-/*
- Blink v3
- Now with 2 variables and an extra LED (remember a ~320 ohms resistor).
- Turns on an LED on for one second, then off for one second, repeatedly.
-
- This example code is in the public domain.
- */
-
-// Pin 13 has an LED connected on most Arduino boards.
-// give it a name:
-int led = 13;
-int red = 12;
-int breve = 200;
-int lunga = 1000;
-
-// the setup routine runs once when you press reset:
-void setup() {
- // initialize the digital pin as an output.
- pinMode(led, OUTPUT);
- pinMode(red, OUTPUT);
-}
-
-// the loop routine runs over and over again forever:
-void loop() {
-lightRed(lunga);
-lightRed(breve);
-
-lightGreen(breve);
-lightGreen(lunga);
-}
-
-void lightRed(int length) { // Argomento
- digitalWrite(red, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(length); // wait for a second
- digitalWrite(red, LOW); // turn the LED off by making the voltage LOW
- delay(length);
-}
-
-void lightGreen(int length) {
- digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(length); // wait for a second
- digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
- delay(length); // wait for a second
-}
-
+++ /dev/null
-/*
- Blink v3
- Now with 2 variables and an extra LED (remember a ~320 ohms resistor).
- Turns on an LED on for one second, then off for one second, repeatedly.
-
- This example code is in the public domain.
- */
-
-// Pin 13 has an LED connected on most Arduino boards.
-// give it a name:
-int led = 13;
-int red = 12;
-int button = 2;
-int breve = 200;
-int lunga = 1000;
-
-// the setup routine runs once when you press reset:
-void setup() {
- // initialize the digital pin as an output.
- pinMode(led, OUTPUT);
- pinMode(red, OUTPUT);
- pinMode(button, INPUT);
-}
-
-// the loop routine runs over and over again forever:
-void loop() {
- if (digitalRead(button) == HIGH) { // HIGH sta per +5v
- lightRed(breve);
- }
- if (digitalRead(button) == LOW) { // LOW sta per 0v
- lightGreen(breve);
- }
-}
-
-void lightRed(int length) { // Argomento
- digitalWrite(red, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(length); // wait for a second
- digitalWrite(red, LOW); // turn the LED off by making the voltage LOW
- delay(length);
-}
-
-void lightGreen(int length) {
- digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(length); // wait for a second
- digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
- delay(length); // wait for a second
-}
-
--- /dev/null
+/*
+ Blink v3
+ Now with 2 variables and an extra LED (remember a ~320 ohms resistor).
+ Turns on an LED on for one second, then off for one second, repeatedly.
+
+ This example code is in the public domain.
+ */
+
+// Pin 13 has an LED connected on most Arduino boards.
+// give it a name:
+int led = 13;
+int breve = 200; // Variabile richiambile nel corso dell'esecuzione
+int lunga = 1000;
+
+// the setup routine runs once when you press reset:
+void setup() {
+ // initialize the digital pin as an output.
+ pinMode(led, OUTPUT);
+}
+
+// the loop routine runs over and over again forever:
+void loop() {
+ digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(breve); // wait for a second
+ digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
+ delay(breve); // wait for a second
+
+ digitalWrite(red, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(lunga); // wait for a second
+ digitalWrite(red, LOW); // turn the LED off by making the voltage LOW
+ delay(lunga);
+}
--- /dev/null
+/*
+ Blink v3
+ Now with 2 variables and an extra LED (remember a ~320 ohms resistor).
+ Turns on an LED on for one second, then off for one second, repeatedly.
+
+ This example code is in the public domain.
+ */
+
+// Pin 13 has an LED connected on most Arduino boards.
+// give it a name:
+int led = 13;
+int breve = 200; // Variabile richiambile nel corso dell'esecuzione
+int lunga = 1000;
+
+// the setup routine runs once when you press reset:
+void setup() {
+ // initialize the digital pin as an output.
+ pinMode(led, OUTPUT);
+}
+
+// the loop routine runs over and over again forever:
+void loop() {
+ rapido(); // accende e spegne rapidamente il LED
+ rapido(); // accende e spegne rapidamente il LED
+ lento(); // accende e spegne lentamente il LED
+}
+
+// Funzioni create dall'utente:
+
+void rapido() {
+ // Accende e spegne rapidamente il LED
+
+ // sequenze di istruzione: accendere e spegnere il LED
+ digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(breve); // wait for a second
+ digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
+ delay(breve); // wait for a second
+}
+
+void lento() {
+ // Accende e spegne lentamente il LED
+
+ // sequenze di istruzione: accendere e spegnere il LED
+ digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(lunga); // wait for a second
+ digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
+ delay(lunga);
+}
+
+
--- /dev/null
+/*
+ Blink v3
+ Now with 2 variables and an extra LED (remember a ~320 ohms resistor).
+ Turns on an LED on for one second, then off for one second, repeatedly.
+
+ This example code is in the public domain.
+ */
+
+// Pin 13 has an LED connected on most Arduino boards.
+// give it a name:
+int led = 13;
+int breve = 200; // Variabile richiambile nel corso dell'esecuzione
+int lunga = 1000;
+int iterator = 0; // Defniamo un variabile per controllare un ciclo iterativo
+
+// the setup routine runs once when you press reset:
+void setup() {
+ // initialize the digital pin as an output.
+ pinMode(led, OUTPUT);
+}
+
+// the loop routine runs over and over again forever:
+void loop() {
+ while (iterator <10) {
+ rapido(); // accende e spegne rapidamente il LED
+ iterator = iterator +1 ; // incrementa l'iteratore
+ // iterator++ ; // equivalente
+ }
+ lento(); // accende e spegne lentamente il LED
+ // Domanda: a quanto equivale iterator ora?
+}
+
+// Funzioni create dall'utente:
+
+void rapido() {
+ // Accende e spegne rapidamente il LED
+
+ // sequenze di istruzione: accendere e spegnere il LED
+ digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(breve); // wait for a second
+ digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
+ delay(breve); // wait for a second
+}
+
+void lento() {
+ // Accende e spegne lentamente il LED
+
+ // sequenze di istruzione: accendere e spegnere il LED
+ digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(lunga); // wait for a second
+ digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
+ delay(lunga);
+}
+
+
--- /dev/null
+/*
+ Blink v3
+ Now with 2 variables and an extra LED (remember a ~320 ohms resistor).
+ Turns on an LED on for one second, then off for one second, repeatedly.
+
+ This example code is in the public domain.
+ */
+
+// Pin 13 has an LED connected on most Arduino boards.
+// give it a name:
+int led = 13;
+int breve = 200; // Variabile richiambile nel corso dell'esecuzione
+int lunga = 1000;
+
+// the setup routine runs once when you press reset:
+void setup() {
+ // initialize the digital pin as an output.
+ pinMode(led, OUTPUT);
+}
+
+// the loop routine runs over and over again forever:
+void loop() {
+ for (int i = 0, i <10, i++) {
+// (Definizione iteratore, condizione di verifica, gestione dell'iteratore)
+ rapido(); // accende e spegne rapidamente il LED
+ }
+
+ lento(); // accende e spegne lentamente il LED
+ // Domanda: dobbiamo preoccuparci dell'iteratore?
+}
+
+// Funzioni create dall'utente:
+
+void rapido() {
+ // Accende e spegne rapidamente il LED
+
+ // sequenze di istruzione: accendere e spegnere il LED
+ digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(breve); // wait for a second
+ digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
+ delay(breve); // wait for a second
+}
+
+void lento() {
+ // Accende e spegne lentamente il LED
+
+ // sequenze di istruzione: accendere e spegnere il LED
+ digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(lunga); // wait for a second
+ digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
+ delay(lunga);
+}
+
+
--- /dev/null
+/*
+ Blink v3
+ Now with 2 variables and an extra LED (remember a ~320 ohms resistor).
+ Turns on an LED on for one second, then off for one second, repeatedly.
+
+ This example code is in the public domain.
+ */
+
+// Pin 13 has an LED connected on most Arduino boards.
+// give it a name:
+int led = 13;
+int red = 12; // Definiamo un altro led
+
+// the setup routine runs once when you press reset:
+void setup() {
+ // initialize the digital pin as an output.
+ pinMode(led, OUTPUT); // Abilitaiamo entrambi i LED
+ pinMode(red, OUTPUT);
+}
+
+// the loop routine runs over and over again forever:
+void loop() {
+ digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(breve); // wait for a second
+ digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
+ delay(breve); // wait for a second
+
+ digitalWrite(red, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(lunga); // wait for a second
+ digitalWrite(red, LOW); // turn the LED off by making the voltage LOW
+ delay(lunga);
+}
--- /dev/null
+/*
+ Blink v6
+
+ Due LEDs con funzioni.
+
+ */
+
+// Pin 13 has an LED connected on most Arduino boards.
+// give it a name:
+int led = 13;
+int red = 12;
+int breve = 200;
+int lunga = 1000;
+
+// the setup routine runs once when you press reset:
+void setup() {
+ // initialize the digital pin as an output.
+ pinMode(led, OUTPUT);
+ pinMode(red, OUTPUT);
+}
+
+// the loop routine runs over and over again forever:
+void loop() {
+ lightRed();
+ lightGreen();
+}
+
+void lightRed() {
+ digitalWrite(red, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(lunga); // wait for a second
+ digitalWrite(red, LOW); // turn the LED off by making the voltage LOW
+ delay(lunga);
+}
+
+void lightGreen() {
+ digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(breve); // wait for a second
+ digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
+ delay(breve); // wait for a second
+}
+
+
--- /dev/null
+/*
+ Blink v7
+
+ Due LEDs con funzioni che accettano argomenti:
+ gli argomenti permettono di modificar il comportamento
+ delle funzioni.
+
+ */
+
+// Pin 13 has an LED connected on most Arduino boards.
+// give it a name:
+int led = 13;
+int red = 12;
+int breve = 200;
+int lunga = 1000;
+
+// the setup routine runs once when you press reset:
+void setup() {
+ // initialize the digital pin as an output.
+ pinMode(led, OUTPUT);
+ pinMode(red, OUTPUT);
+}
+
+// the loop routine runs over and over again forever:
+void loop() {
+lightRed(lunga);
+lightRed(breve);
+
+lightGreen(breve);
+lightGreen(lunga);
+}
+
+void lightRed(int length) { // Argomento
+ digitalWrite(red, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(length); // wait for a second
+ digitalWrite(red, LOW); // turn the LED off by making the voltage LOW
+ delay(length);
+}
+
+void lightGreen(int length) {
+ digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(length); // wait for a second
+ digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
+ delay(length); // wait for a second
+}
+
--- /dev/null
+// From http://www.electrodragon.com/w/Dot_Matrix_Display_Kit_w/MAX7219_IC,_PCB
+
+unsigned char i;
+unsigned char j;
+/*Port Definitions*/
+int Max7219_pinCLK = 10;
+int Max7219_pinCS = 9;
+int Max7219_pinDIN = 8;
+
+unsigned char disp1[38][8]={
+ {
+ 0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C }
+ ,//0
+ {
+ 0x10,0x18,0x14,0x10,0x10,0x10,0x10,0x10 }
+ ,//1
+ {
+ 0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E }
+ ,//2
+ {
+ 0x3E,0x2,0x2,0x3E,0x2,0x2,0x3E,0x0 }
+ ,//3
+ {
+ 0x8,0x18,0x28,0x48,0xFE,0x8,0x8,0x8 }
+ ,//4
+ {
+ 0x3C,0x20,0x20,0x3C,0x4,0x4,0x3C,0x0 }
+ ,//5
+ {
+ 0x3C,0x20,0x20,0x3C,0x24,0x24,0x3C,0x0 }
+ ,//6
+ {
+ 0x3E,0x22,0x4,0x8,0x8,0x8,0x8,0x8 }
+ ,//7
+ {
+ 0x0,0x3E,0x22,0x22,0x3E,0x22,0x22,0x3E }
+ ,//8
+ {
+ 0x3E,0x22,0x22,0x3E,0x2,0x2,0x2,0x3E }
+ ,//9
+ {
+ 0x8,0x14,0x22,0x3E,0x22,0x22,0x22,0x22 }
+ ,//A
+ {
+ 0x3C,0x22,0x22,0x3E,0x22,0x22,0x3C,0x0 }
+ ,//B
+ {
+ 0x3C,0x40,0x40,0x40,0x40,0x40,0x3C,0x0 }
+ ,//C
+ {
+ 0x7C,0x42,0x42,0x42,0x42,0x42,0x7C,0x0 }
+ ,//D
+ {
+ 0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x7C }
+ ,//E
+ {
+ 0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x40 }
+ ,//F
+ {
+ 0x3C,0x40,0x40,0x40,0x40,0x44,0x44,0x3C }
+ ,//G
+ {
+ 0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x44 }
+ ,//H
+ {
+ 0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x7C }
+ ,//I
+ {
+ 0x3C,0x8,0x8,0x8,0x8,0x8,0x48,0x30 }
+ ,//J
+ {
+ 0x0,0x24,0x28,0x30,0x20,0x30,0x28,0x24 }
+ ,//K
+ {
+ 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7C }
+ ,//L
+ {
+ 0x81,0xC3,0xA5,0x99,0x81,0x81,0x81,0x81 }
+ ,//M
+ {
+ 0x0,0x42,0x62,0x52,0x4A,0x46,0x42,0x0 }
+ ,//N
+ {
+ 0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C }
+ ,//O
+ {
+ 0x3C,0x22,0x22,0x22,0x3C,0x20,0x20,0x20 }
+ ,//P
+ {
+ 0x1C,0x22,0x22,0x22,0x22,0x26,0x22,0x1D }
+ ,//Q
+ {
+ 0x3C,0x22,0x22,0x22,0x3C,0x24,0x22,0x21 }
+ ,//R
+ {
+ 0x0,0x1E,0x20,0x20,0x3E,0x2,0x2,0x3C }
+ ,//S
+ {
+ 0x0,0x3E,0x8,0x8,0x8,0x8,0x8,0x8 }
+ ,//T
+ {
+ 0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1C }
+ ,//U
+ {
+ 0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18 }
+ ,//V
+ {
+ 0x0,0x49,0x49,0x49,0x49,0x2A,0x1C,0x0 }
+ ,//W
+ {
+ 0x0,0x41,0x22,0x14,0x8,0x14,0x22,0x41 }
+ ,//X
+ {
+ 0x41,0x22,0x14,0x8,0x8,0x8,0x8,0x8 }
+ ,//Y
+ {
+ 0x0,0x7F,0x2,0x4,0x8,0x10,0x20,0x7F }
+ ,//Z
+};
+
+
+
+void Write_Max7219_byte(unsigned char DATA)
+{
+ unsigned char i;
+ digitalWrite(Max7219_pinCS,LOW);
+ for(i=8;i>=1;i--)
+ {
+ digitalWrite(Max7219_pinCLK,LOW);
+ digitalWrite(Max7219_pinDIN,DATA&0x80);// Extracting a bit data
+ DATA = DATA<<1;
+ digitalWrite(Max7219_pinCLK,HIGH);
+ }
+}
+
+
+void Write_Max7219(unsigned char address,unsigned char dat)
+{
+ digitalWrite(Max7219_pinCS,LOW);
+ Write_Max7219_byte(address); //address,code of LED
+ Write_Max7219_byte(dat); //data,figure on LED
+ digitalWrite(Max7219_pinCS,HIGH);
+}
+
+void Init_MAX7219(void)
+{
+ Write_Max7219(0x09, 0x00); //decoding :BCD
+ Write_Max7219(0x0a, 0x03); //brightness
+ Write_Max7219(0x0b, 0x07); //scanlimit;8 LEDs
+ Write_Max7219(0x0c, 0x01); //power-down mode:0,normal mode:1
+ Write_Max7219(0x0f, 0x00); //test display:1;EOT,display:0
+}
+
+
+
+void setup()
+{
+
+ pinMode(Max7219_pinCLK,OUTPUT);
+ pinMode(Max7219_pinCS,OUTPUT);
+ pinMode(Max7219_pinDIN,OUTPUT);
+ delay(50);
+ Init_MAX7219();
+}
+
+
+void loop()
+{
+ for(j=0;j<38;j++)
+ {
+ for(i=1;i<9;i++)
+ Write_Max7219(i,disp1[j][i-1]);
+ delay(500);
+ }
+}
+
--- /dev/null
+/* YourDuino.com Example Software Sketch
+ Small Stepper Motor and Driver V1.3 11/30/2013
+ http://arduino-direct.com/sunshop/index.php?l=product_detail&p=126
+ Shows 4-step sequence, Then 1/2 turn and back different speeds
+ terry@yourduino.com */
+
+/*-----( Import needed libraries )-----*/
+#include <Stepper.h>
+
+/*-----( Declare Constants, Pin Numbers )-----*/
+//---( Number of steps per revolution of INTERNAL motor in 4-step mode )---
+#define STEPS_PER_MOTOR_REVOLUTION 32
+
+//---( Steps per OUTPUT SHAFT of gear reduction )---
+#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64 //2048
+
+/*-----( Declare objects )-----*/
+// create an instance of the stepper class, specifying
+// the number of steps of the motor and the pins it's
+// attached to
+
+//The pin connections need to be 4 pins connected
+// to Motor Driver In1, In2, In3, In4 and then the pins entered
+// here in the sequence 1-3-2-4 for proper sequencing
+Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);
+
+
+/*-----( Declare Variables )-----*/
+int Steps2Take;
+
+void setup() /*----( SETUP: RUNS ONCE )----*/
+{
+// Nothing (Stepper Library sets pins as outputs)
+}/*--(end setup )---*/
+
+void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
+{
+ small_stepper.setSpeed(1); // SLOWLY Show the 4 step sequence
+ Steps2Take = 4; // Rotate CW
+ small_stepper.step(Steps2Take);
+ delay(2000);
+
+ Steps2Take = STEPS_PER_OUTPUT_REVOLUTION / 2; // Rotate CW 1/2 turn
+ small_stepper.setSpeed(100);
+ small_stepper.step(Steps2Take);
+ delay(1000);
+
+ Steps2Take = - STEPS_PER_OUTPUT_REVOLUTION / 2; // Rotate CCW 1/2 turn
+ small_stepper.setSpeed(700); // 700 a good max speed??
+ small_stepper.step(Steps2Take);
+ delay(2000);
+
+}/* --(end main loop )-- */
+
+/* ( THE END ) */
+
--- /dev/null
+
+
+/*
+ BYJ48 Stepper motor code
+ Connect :
+ IN1 >> D8
+ IN2 >> D9
+ IN3 >> D10
+ IN4 >> D11
+ VCC ... 5V Prefer to use external 5V Source
+ Gnd
+ written By :Mohannad Rawashdeh
+ http://www.instructables.com/member/Mohannad+Rawashdeh/
+ 28/9/2013
+ */
+
+#define IN1 8
+#define IN2 9
+#define IN3 10
+#define IN4 11
+int Steps = 0;
+boolean Direction = true;// gre
+unsigned long last_time;
+unsigned long currentMillis ;
+int steps_left=4095;
+long time;
+void setup()
+{
+ Serial.begin(115200);
+ pinMode(IN1, OUTPUT);
+ pinMode(IN2, OUTPUT);
+ pinMode(IN3, OUTPUT);
+ pinMode(IN4, OUTPUT);
+ // delay(1000);
+
+}
+void loop()
+{
+ while(steps_left>0){
+ currentMillis = micros();
+ if(currentMillis-last_time>=1000){
+ stepper(1);
+ time=time+micros()-last_time;
+ last_time=micros();
+ steps_left--;
+ }
+ }
+ Serial.println(time);
+ Serial.println("Wait...!");
+ delay(2000);
+ Direction=!Direction;
+ steps_left=4095;
+}
+
+void stepper(int xw){
+ for (int x=0;x<xw;x++){
+ switch(Steps){
+ case 0:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, HIGH);
+ break;
+ case 1:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, HIGH);
+ digitalWrite(IN4, HIGH);
+ break;
+ case 2:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, HIGH);
+ digitalWrite(IN4, LOW);
+ break;
+ case 3:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, HIGH);
+ digitalWrite(IN3, HIGH);
+ digitalWrite(IN4, LOW);
+ break;
+ case 4:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, HIGH);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ case 5:
+ digitalWrite(IN1, HIGH);
+ digitalWrite(IN2, HIGH);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ case 6:
+ digitalWrite(IN1, HIGH);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ case 7:
+ digitalWrite(IN1, HIGH);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, HIGH);
+ break;
+ default:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ }
+ SetDirection();
+ }
+}
+void SetDirection(){
+ if(Direction==1){
+ Steps++;
+ }
+ if(Direction==0){
+ Steps--;
+ }
+ if(Steps>7){
+ Steps=0;
+ }
+ if(Steps<0){
+ Steps=7;
+ }
+}
+
+
--- /dev/null
+/* YourDuinoStarter Example: 2 Stepper Motors
+ - WHAT IT DOES: Runs 2 28BYJ-48 stepper motors with AccelStepper Library
+ - Motors accelerate and decelerate simultaneously in opposite rotations
+ - SEE the comments after "//" on each line below
+ - Derived from example code by Mike McCauley
+ - modified by Celem for single stepper
+ - modified by lowres for two steppers
+ NOTE: This may not run 2 motors from USB.
+ May need separate +5 Supply for motors
+ - CONNECTIONS: See Pin definitions below
+
+ - V1.01 11/30/2013
+ Questions: terry@yourduino.com */
+
+/*-----( Import needed libraries )-----*/
+#include <AccelStepper.h>
+/*-----( Declare Constants and Pin Numbers )-----*/
+#define FULLSTEP 4
+#define HALFSTEP 8
+// motor pins
+#define motorPin1 4 // Blue - 28BYJ48 pin 1
+#define motorPin2 5 // Pink - 28BYJ48 pin 2
+#define motorPin3 6 // Yellow - 28BYJ48 pin 3
+#define motorPin4 7 // Orange - 28BYJ48 pin 4
+ // Red - 28BYJ48 pin 5 (VCC)
+
+#define motorPin5 8 // Blue - 28BYJ48 pin 1
+#define motorPin6 9 // Pink - 28BYJ48 pin 2
+#define motorPin7 10 // Yellow - 28BYJ48 pin 3
+#define motorPin8 11 // Orange - 28BYJ48 pin 4
+ // Red - 28BYJ48 pin 5 (VCC)
+/*-----( Declare objects )-----*/
+// NOTE: The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48
+AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
+AccelStepper stepper2(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8);
+
+/*-----( Declare Variables )-----*/
+//none
+
+void setup() /****** SETUP: RUNS ONCE ******/
+{
+ stepper1.setMaxSpeed(1000.0);
+ stepper1.setAcceleration(50.0);
+ stepper1.setSpeed(200);
+ stepper1.moveTo(2048); // 1 revolution
+
+ stepper2.setMaxSpeed(1000.0);
+ stepper2.setAcceleration(50.0);
+ stepper2.setSpeed(200);
+ stepper2.moveTo(-2048); // 1 revolution
+
+}//--(end setup )---
+
+
+void loop() /****** LOOP: RUNS CONSTANTLY ******/
+{
+ //Change direction at the limits
+ if (stepper1.distanceToGo() == 0)
+ stepper1.moveTo(-stepper1.currentPosition());
+ if (stepper2.distanceToGo() == 0)
+ stepper2.moveTo(-stepper2.currentPosition());
+
+ stepper1.run();
+ stepper2.run();
+
+}//--(end main loop )---
+
+/*-----( Declare User-written Functions )-----*/
+//none
+//*********( THE END )***********
--- /dev/null
+
+/*
+ Stepper Motor Control - one revolution
+
+ Revisionato per i motori 5v 28YBJ-48 con controller board
+ - http://arduino-info.wikispaces.com/SmallSteppers
+
+ This program drives a unipolar or bipolar stepper motor.
+ The motor is attached to digital pins 8 - 11 of the Arduino.
+
+ The motor should revolve one revolution in one direction, then
+ one revolution in the other direction.
+
+
+ Created 11 Mar. 2007
+ Modified 30 Nov. 2009
+ by Tom Igoe
+
+ */
+
+#include <Stepper.h>
+
+const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
+// for your motor
+// 2048 = 360deg = 32*64 in 4-step sequence as in Step Library
+// 1025 = 180deg
+// 512.5 = 90deg
+// 5.6944 = 1deg
+
+// initialize the stepper library on pins 8 through 11:
+Stepper myStepper(stepsPerRevolution,8,10,9,11);
+// Sequence is 1-3-2-4
+// Valid values: (8,10,11,9), (9,11,8,10), (10,8,9,11), and (11,9,10,8)
+// 1N1 on pin 8
+// 1N2 on pin 9
+// 1N3 on pin 10
+// 1N4 on pin 11
+// powered via 5v
+// Max speed is 14RPM @ 5v
+
+void setup() {
+ // set the speed at 60 rpm:
+ myStepper.setSpeed(14); // Max speed is 14RPM @5v
+ // initialize the serial port:
+ Serial.begin(9600);
+}
+
+void loop() {
+ // step one revolution in one direction:
+ Serial.println("clockwise");
+ myStepper.step(stepsPerRevolution);
+ delay(500);
+
+ // step one revolution in the other direction:
+ Serial.println("counterclockwise");
+ myStepper.step(-stepsPerRevolution);
+ delay(500);
+}
+
digitalWrite(latchPin, LOW);
// shift out the bits:
- shiftOut(dataPin, clockPin, SBFIRST, numberToDisplay);
+ shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);