From: Andrea Manni <andrea@piffa.net>
Date: Thu, 17 Dec 2015 15:41:14 +0000 (+0100)
Subject: array
X-Git-Url: http://git.piffa.net/web?a=commitdiff_plain;h=7eb899c40c1fc5f52e0f9c016e6f638f51fe14ff;p=sketchbook_andrea

array
---

diff --git a/.gitignore b/.gitignore
index 34f7b71..88adc95 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@ TODO
 push.sh
 libraries/aero/
 *.swp
+*Makefile
+*tags
diff --git a/README b/README
index d795d3f..5c66ec0 100644
--- a/README
+++ b/README
@@ -190,3 +190,22 @@ Utilizzare specifici devices:
 - connessione seriale via radio 
 - programmare un Attiny85 con Arduino
 - ethernet e WIFI
+
+Makefile
+============
+
+Avendo installato il pacchetto ``arduino-mk``, con l'IDE /usr/local/software/arduino-1.6.5 , Arduino.mk resta quello originale della distribuzione posto in /usr/share/arduino/ .
+
+/usr/share/arduino/Makefile ::
+
+    # Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
+
+    BOARD_TAG       = uno
+    MONITOR_PORT    = /dev/ttyACM0
+
+    CURRENT_DIR     = $(shell pwd)
+    OBJDIR          = /tmp/$(notdir $(shell pwd))
+    ARDUINO_DIR     = /usr/local/software/arduino-1.6.5
+    MONITOR_BAUDRATE = 115200
+
+    include /usr/share/arduino/Arduino.mk
diff --git a/RGB_LED/rgb_0/rgb_0.ino b/RGB_LED/rgb_0/rgb_0.ino
index 2290582..d69d451 100644
--- a/RGB_LED/rgb_0/rgb_0.ino
+++ b/RGB_LED/rgb_0/rgb_0.ino
@@ -7,9 +7,9 @@
  Schema: http://lab.piffa.net/schemi/rgb.jpg
  */
 
-int redPin = 11;
-int greenPin = 10;
-int bluePin = 9;
+int redPin      = 11;   // 2v a 20ma: che resistenza dovro usare?
+int greenPin    = 10;   // 3.5v a 20ma: che resistenza dovro usare?
+int bluePin     = 9;    // 3.5v a 20ma: che resistenza dovro usare?
 
 
 
diff --git a/RGB_LED/rgb_0_soluzione/rgb_0_soluzione.ino b/RGB_LED/rgb_0_soluzione/rgb_0_soluzione.ino
index b9fb952..5d46d7e 100644
--- a/RGB_LED/rgb_0_soluzione/rgb_0_soluzione.ino
+++ b/RGB_LED/rgb_0_soluzione/rgb_0_soluzione.ino
@@ -5,10 +5,9 @@
  common anode
  */
 
-int redPin = 11;
-int greenPin = 10;
-int bluePin = 9;
-
+int redPin      = 11;   // 2v a 20ma: che resistenza dovro usare?
+int greenPin    = 10;   // 3.5v a 20ma: che resistenza dovro usare?
+int bluePin     = 9;    // 3.5v a 20ma: che resistenza dovro usare?
 
 
 void setup()
diff --git a/motors/stepper/step_3_half_step/step_3_half_step.ino b/motors/stepper/step_3_half_step/step_3_half_step.ino
index 3f1c85c..6059883 100644
--- a/motors/stepper/step_3_half_step/step_3_half_step.ino
+++ b/motors/stepper/step_3_half_step/step_3_half_step.ino
@@ -24,6 +24,10 @@ unsigned long last_time;
 unsigned long currentMillis ;
 int steps_left=4095;
 long time;
+
+void SetDirection();
+void stepper(int xw);
+
 void setup()
 {
   Serial.begin(115200);
diff --git a/piezo/piezo_2_keyboard/piezo_2_keyboard.ino b/piezo/piezo_2_keyboard/piezo_2_keyboard.ino
index 01afcd8..2df467f 100644
--- a/piezo/piezo_2_keyboard/piezo_2_keyboard.ino
+++ b/piezo/piezo_2_keyboard/piezo_2_keyboard.ino
@@ -1,56 +1,66 @@
+
 /*
- Melody keyboard with Input Pullup Serial
+ Melody keyboard with Input Pullup
  Plays a pitch that changes based on 3 digital inputs
- 
- This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a 
+
+ This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a
  digital input on pin 2 and prints the results to the serial monitor.
- 
+ There's also an extensive use of arrays.
+
  Thecircuit:
  * 3 buttons in pin 2,3,4 with no resistors
  * Piezo on digital pin 9
  * Serial debug is available
- 
+
  This example code is in the public domain
- 
+
  Circuit: http://lab.piffa.net/schemi/piezo_2_keyboard_bb.png
- 
- */
 
+ */
 
-int input[]= {
-  1,2,3};
-int notes[] = {
-  262, 392,880 }; // suona una prima, quinta, ottava in C4
+const int tasti[]= {4,3,2}; // La nota piu' a sx e' quella piu' bassa
+const int notes[] = {262, 392, 880}; // suona una prima, quinta, ottava in C4
+const int piezo_pin = 9;
 
 // Carica un file di esempio con tutte le note
 // #include "pitches.h";
 // int notes[] = {NOTE_C4, NOTE_G4,NOTE_C5 }; // suona una prima, quinta, ottava
 
-void setup(){
-  //start serial connection
-  Serial.begin(9600);
-  //configure pin2/3/4 as an input and enable the internal pull-up resistor
-  pinMode(2, INPUT_PULLUP);
-  pinMode(3, INPUT_PULLUP);
-  pinMode(4, INPUT_PULLUP);
-  pinMode(9, OUTPUT); 
+void setup() {
+    //start serial connection
+    Serial.begin(9600);
+    Serial.println("Welcome");
+    //configure pin2/3/4 as an input and enable the internal pull-up resistor
+    pinMode(tasti[0], INPUT_PULLUP);
+    pinMode(tasti[1], INPUT_PULLUP);
+    pinMode(tasti[2], INPUT_PULLUP);    // Provare ad impostare i PIN con un
+                                        // ciclo for
+    pinMode(9, OUTPUT);
 }
 
-void loop(){
-  for (int thisSensor = 2; thisSensor < 5; thisSensor++) {
-    int sensorReading = digitalRead(thisSensor);
-    if (sensorReading == LOW) {
-      Serial.println(thisSensor);
-      tone(9, notes[thisSensor -2], 50); // Notes array is translated
+void loop() {
+    for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
+        int sensorReading = digitalRead(tasti[thisSensor]);
+        if (sensorReading == LOW) {
+            Serial.print("Sensore: ");
+            Serial.print(thisSensor);
+            tone(piezo_pin, notes[thisSensor ], 50); // Notes array is translated
+            Serial.print("\t Nota: ");
+            Serial.println(notes[thisSensor]);
+        }
+        //delay(2); // eventuale delay
     }
-    //delay(2); // eventuale delay
-  }
 }
 /* Domande
  1. Modificare le note suonate utilizzando come riferimento il file pitches.h:
- suonare una prima, terza, quinta (C-E-G)
- 2. Includere il file pitches.h . Come si potrebbe scrivere una melodia da far suonare
- autnomamente ad Arduino?
+    suonare una prima, terza, quinta (C-E-G)
+ 2. Includere il file pitches.h . Come si potrebbe scrivere una melodia da far s    uonare autnomamente ad Arduino?
  */
 
 
+
+
+
+
+
+
diff --git a/programming/loops/loop_0_rider/loop_0_rider.ino b/programming/loops/loop_0_rider/loop_0_rider.ino
new file mode 100644
index 0000000..854f225
--- /dev/null
+++ b/programming/loops/loop_0_rider/loop_0_rider.ino
@@ -0,0 +1,110 @@
+/* Knight Rider 1
+ * --------------
+ *
+ * Basically an extension of Blink_LED.
+ *
+ *
+ * (cleft) 2005 K3, Malmo University
+ * @author: David Cuartielles
+ * @hardware: David Cuartielles, Aaron Hallborg
+   See: https://www.arduino.cc/en/Tutorial/KnightRider
+
+   Schema semplificato: 
+   - http://lab.piffa.net/schemi/8_led_single_res_bb.png
+   - http://lab.piffa.net/schemi/8_led_single_res_schem.png
+ */
+
+int pin2 = 2;
+int pin3 = 3;
+int pin4 = 4;
+int pin5 = 5;
+int pin6 = 6;
+int pin7 = 7;
+int pin7 = 8;
+int pin7 = 9;
+int timer = 100;
+
+void setup(){
+  pinMode(pin2, OUTPUT);
+  pinMode(pin3, OUTPUT);
+  pinMode(pin4, OUTPUT);
+  pinMode(pin5, OUTPUT);
+  pinMode(pin6, OUTPUT);
+  pinMode(pin7, OUTPUT);
+  pinMode(pin8, OUTPUT);
+  pinMode(pin9, OUTPUT);
+}
+
+void loop() {
+   digitalWrite(pin2, HIGH);
+   delay(timer);
+   digitalWrite(pin2, LOW);
+   delay(timer);
+
+   digitalWrite(pin3, HIGH);
+   delay(timer);
+   digitalWrite(pin3, LOW);
+   delay(timer);
+
+   digitalWrite(pin4, HIGH);
+   delay(timer);
+   digitalWrite(pin4, LOW);
+   delay(timer);
+
+   digitalWrite(pin5, HIGH);
+   delay(timer);
+   digitalWrite(pin5, LOW);
+   delay(timer);
+
+   digitalWrite(pin6, HIGH);
+   delay(timer);
+   digitalWrite(pin6, LOW);
+   delay(timer);
+
+   digitalWrite(pin7, HIGH);
+   delay(timer);
+   digitalWrite(pin7, LOW);
+   delay(timer);
+
+   digitalWrite(pin8, HIGH);
+   delay(timer);
+   digitalWrite(pin8, LOW);
+   delay(timer);
+
+   digitalWrite(pin9, HIGH);
+   delay(timer);
+   digitalWrite(pin9, LOW);
+   delay(timer);
+
+   // Ding! Mezzo giro
+
+   digitalWrite(pin8, HIGH);
+   delay(timer);
+   digitalWrite(pin8, LOW);
+   delay(timer);
+   
+   digitalWrite(pin7, HIGH);
+   delay(timer);
+   digitalWrite(pin7, LOW);
+   delay(timer);
+
+   digitalWrite(pin6, HIGH);
+   delay(timer);
+   digitalWrite(pin6, LOW);
+   delay(timer);
+
+   digitalWrite(pin5, HIGH);
+   delay(timer);
+   digitalWrite(pin5, LOW);
+   delay(timer);
+
+   digitalWrite(pin4, HIGH);
+   delay(timer);
+   digitalWrite(pin4, LOW);
+   delay(timer);
+
+   digitalWrite(pin3, HIGH);
+   delay(timer);
+   digitalWrite(pin3, LOW);
+   delay(timer);
+}
diff --git a/programming/loops/loop_1_array_loop/loop_1_array_loop.ino b/programming/loops/loop_1_array_loop/loop_1_array_loop.ino
new file mode 100644
index 0000000..42871ef
--- /dev/null
+++ b/programming/loops/loop_1_array_loop/loop_1_array_loop.ino
@@ -0,0 +1,70 @@
+/* Knight Rider 2
+ * --------------
+ *
+ * Reducing the amount of code using for(;;).
+ *
+ *
+ * (cleft) 2005 K3, Malmo University
+ * @author: David Cuartielles
+ * @hardware: David Cuartielles, Aaron Hallborg
+
+
+   Schema semplificato: 
+   - http://lab.piffa.net/schemi/8_led_single_res_bb.png
+   - http://lab.piffa.net/schemi/8_led_single_res_schem.png
+ */
+
+int pinArray[8] = {2, 3, 4, 5, 6, 7, 8, 9};
+int count = 0;
+int timer = 100;
+
+void setup(){
+  // we make all the declarations at once
+  for (count=0;count<9;count++) {
+    pinMode(pinArray[count], OUTPUT);
+  }
+}
+
+void loop() {
+  for (count=0;count<8;count++) { // 8 e' un numero magico
+   digitalWrite(pinArray[count], HIGH);
+   delay(timer);
+   digitalWrite(pinArray[count], LOW);
+   delay(timer);
+  }
+  for (count=8;count>=0;count--) {
+   digitalWrite(pinArray[count], HIGH);
+   delay(timer);
+   digitalWrite(pinArray[count], LOW);
+   delay(timer);
+  }
+}
+
+/* Domande:
+ 
+ 1. Come posso fare per saltare un elemento del loop? 
+ 2. Come posso fare per uscire completamente dal loop? 
+ 3. 8 e' un numero magico: come posso evitarlo?
+
+.
+.
+.
+.
+.
+.
+.
+.
+.
+.
+.
+Soluzioni: 
+ 1. utilizzare continue
+ 2. utilizzare break
+ 3. Utilizzare un variabile sarebbe gia' un inizio, ancora meglio estrarre il
+    valore tramite la funzione sizeof().
+Links: 
+- http://www.tutorialspoint.com/cprogramming/c_continue_statement.htm
+- https://www.arduino.cc/en/Reference/Sizeof
+*/
+
+