From 2e29cbe13965809a5d3866ccdc12b1d665b54115 Mon Sep 17 00:00:00 2001 From: eaman Date: Wed, 21 Dec 2016 12:25:48 +0100 Subject: [PATCH] clean up --- RGB_LED/README | 9 +- .../avr_greadboard}/boards.txt | 0 .../ATmegaBOOT_168_atmega328_pro_8MHz.hex | 0 .../shiftOut_binary_count.ino | 0 .../shift_register_8bit.ino | 0 .../shift_register_custom_pattern_4.ino | 0 .../shift_register_pattern.ino | 0 .../sketch_jan27c/sketch_jan27c.ino | 0 .../shift_register_serial.ino | 0 .../BlinkWithoutDelay_1.ino | 82 ----------------- .../BlinkWithoutDelay_2_led.ino | 88 ------------------- .../BlinkWithoutDelay_2_led_cleanup.ino | 77 ---------------- oggi/blink_0/blink_0.ino | 29 ------ oggi/blink_0_soluzione/blink_0_soluzione.ino | 81 ----------------- ...ta_types_bin_hex_transformation_serial.ino | 40 --------- .../argomenti_2/argomenti_2.ino | 7 ++ .../blink_with_functions.ino | 2 +- .../blink_with_functions/funzioni.ino | 0 .../scope_1/scope_1.ino | 0 .../head_tails_ino/head_tails_ino.ino | 10 ++- .../leap_year_functions.ino | 80 ----------------- serial/README | 3 + 22 files changed, 25 insertions(+), 483 deletions(-) rename {breadboard/avr => advanced_projects/avr_greadboard}/boards.txt (100%) rename {breadboard/avr => advanced_projects/avr_greadboard}/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex (100%) rename {shift_register => hardware/shift_register}/shiftOut_binary_count/shiftOut_binary_count.ino (100%) rename {shift_register => hardware/shift_register}/shift_register_8bit/shift_register_8bit.ino (100%) rename {shift_register => hardware/shift_register}/shift_register_custom_pattern_4/shift_register_custom_pattern_4.ino (100%) rename {shift_register => hardware/shift_register}/shift_register_pattern/shift_register_pattern.ino (100%) rename {shift_register => hardware/shift_register}/shift_register_pattern/sketch_jan27c/sketch_jan27c.ino (100%) rename {shift_register => hardware/shift_register}/shift_register_serial/shift_register_serial.ino (100%) delete mode 100644 oggi/BlinkWithoutDelay_1/BlinkWithoutDelay_1.ino delete mode 100644 oggi/BlinkWithoutDelay_2_led/BlinkWithoutDelay_2_led.ino delete mode 100644 oggi/BlinkWithoutDelay_2_led_cleanup/BlinkWithoutDelay_2_led_cleanup.ino delete mode 100644 oggi/blink_0/blink_0.ino delete mode 100644 oggi/blink_0_soluzione/blink_0_soluzione.ino delete mode 100644 programming/data_types_bin_hex_transformation_serial/data_types_bin_hex_transformation_serial.ino rename programming/{functions => funzioni}/argomenti_2/argomenti_2.ino (70%) rename programming/{ => funzioni}/blink_with_functions/blink_with_functions.ino (86%) rename programming/{ => funzioni}/blink_with_functions/funzioni.ino (100%) rename programming/{functions => funzioni}/scope_1/scope_1.ino (100%) rename programming/{conditional_test => }/head_tails_ino/head_tails_ino.ino (96%) delete mode 100644 programming/leap_year_functions/leap_year_functions.ino diff --git a/RGB_LED/README b/RGB_LED/README index 133660a..c9a9ede 100644 --- a/RGB_LED/README +++ b/RGB_LED/README @@ -1,2 +1,9 @@ -Ottima lezione in italiano: +La serie degli esercizi sui LED RGB introduce argomenti come: + +- Forme di dati strutturate: array associativi +- Programmazione ad oggetti per rappresentare un LED RGB (vedi anche + la serie multitasking per refactoring, scope delle variabili / + proprieta'). + +Ottima lezione in italiano sul componente: - http://www.maffucci.it/2014/09/27/arduino-lezione-09-uso-di-led-rgb-parte-1/ diff --git a/breadboard/avr/boards.txt b/advanced_projects/avr_greadboard/boards.txt similarity index 100% rename from breadboard/avr/boards.txt rename to advanced_projects/avr_greadboard/boards.txt diff --git a/breadboard/avr/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex b/advanced_projects/avr_greadboard/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex similarity index 100% rename from breadboard/avr/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex rename to advanced_projects/avr_greadboard/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex diff --git a/shift_register/shiftOut_binary_count/shiftOut_binary_count.ino b/hardware/shift_register/shiftOut_binary_count/shiftOut_binary_count.ino similarity index 100% rename from shift_register/shiftOut_binary_count/shiftOut_binary_count.ino rename to hardware/shift_register/shiftOut_binary_count/shiftOut_binary_count.ino diff --git a/shift_register/shift_register_8bit/shift_register_8bit.ino b/hardware/shift_register/shift_register_8bit/shift_register_8bit.ino similarity index 100% rename from shift_register/shift_register_8bit/shift_register_8bit.ino rename to hardware/shift_register/shift_register_8bit/shift_register_8bit.ino diff --git a/shift_register/shift_register_custom_pattern_4/shift_register_custom_pattern_4.ino b/hardware/shift_register/shift_register_custom_pattern_4/shift_register_custom_pattern_4.ino similarity index 100% rename from shift_register/shift_register_custom_pattern_4/shift_register_custom_pattern_4.ino rename to hardware/shift_register/shift_register_custom_pattern_4/shift_register_custom_pattern_4.ino diff --git a/shift_register/shift_register_pattern/shift_register_pattern.ino b/hardware/shift_register/shift_register_pattern/shift_register_pattern.ino similarity index 100% rename from shift_register/shift_register_pattern/shift_register_pattern.ino rename to hardware/shift_register/shift_register_pattern/shift_register_pattern.ino diff --git a/shift_register/shift_register_pattern/sketch_jan27c/sketch_jan27c.ino b/hardware/shift_register/shift_register_pattern/sketch_jan27c/sketch_jan27c.ino similarity index 100% rename from shift_register/shift_register_pattern/sketch_jan27c/sketch_jan27c.ino rename to hardware/shift_register/shift_register_pattern/sketch_jan27c/sketch_jan27c.ino diff --git a/shift_register/shift_register_serial/shift_register_serial.ino b/hardware/shift_register/shift_register_serial/shift_register_serial.ino similarity index 100% rename from shift_register/shift_register_serial/shift_register_serial.ino rename to hardware/shift_register/shift_register_serial/shift_register_serial.ino diff --git a/oggi/BlinkWithoutDelay_1/BlinkWithoutDelay_1.ino b/oggi/BlinkWithoutDelay_1/BlinkWithoutDelay_1.ino deleted file mode 100644 index b7a04a9..0000000 --- a/oggi/BlinkWithoutDelay_1/BlinkWithoutDelay_1.ino +++ /dev/null @@ -1,82 +0,0 @@ -/* Blink without Delay - - Utilizziamo la funzione millis() al posto di delay() - per poter gestire il lampeggio di un LED senza bloccare - il processore. - - Questo esercizio e' strutturato in una serie di passaggi incrementali - nei quali una versione minimale si evolve per introdurre - programmazione ad oggetti, interrupts, pointers. - - Turns on and off a light emitting diode(LED) connected to a digital - pin, without using the delay() function. This means that other code - can run at the same time without being interrupted by the LED code. - - The circuit: - * LED attached from pin 13 to ground. - * Note: on most Arduinos, there is already an LED on the board - that's attached to pin 13, so no hardware is needed for this example. - - - created 2005 - by David A. Mellis - modified 8 Feb 2010 - by Paul Stoffregen - 2015 modified by Andrea Manni - - This example code is in the public domain. - - - http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay - */ - -// constants won't change. Used here to -// set pin numbers: -const int ledPin = 13; - -// Variables will change: -int ledState = LOW; // ledState used to set the LED -long previousMillis = 0; // will store last time LED was updated - -// the follow variables is a long because the time, measured in miliseconds, -// will quickly become a bigger number than can be stored in an int. -const long interval = 1000; // interval at which to blink (milliseconds) - -void setup() { - // set the digital pin as output: - pinMode(ledPin, OUTPUT); -} - -void loop() -{ - // here is where you'd put code that needs to be running all the time. - - // check to see if it's time to blink the LED; that is, if the - // difference between the current time and last time you blinked - // the LED is bigger than the interval at which you want to - // blink the LED. - - if (millis() > previousMillis + interval) { - // Aggiorniamo il contatore previousMillis - previousMillis = millis(); - - // if the LED is off turn it on and vice-versa: - if (ledState == LOW) - ledState = HIGH; - else - ledState = LOW; - // e' possibile semplificare questa operazione? - // Hint: lo stato del LED e' binario: ha solo due stati possibili. - - // set the LED with the ledState of the variable: - digitalWrite(ledPin, ledState); - } -} - -/* Domande - 1. Aggioungere un LED che brilli ogni 500ms: iniziare pensando - a quali variabili gestiscono l'attuale LED e a quali si - dovranno aggiungere. - 2. E' ora agevole cambiare gli intervalli dei due LED? - Modificare gli intervalli dei due led (es 500ms - 320ms) - */ diff --git a/oggi/BlinkWithoutDelay_2_led/BlinkWithoutDelay_2_led.ino b/oggi/BlinkWithoutDelay_2_led/BlinkWithoutDelay_2_led.ino deleted file mode 100644 index 2100ead..0000000 --- a/oggi/BlinkWithoutDelay_2_led/BlinkWithoutDelay_2_led.ino +++ /dev/null @@ -1,88 +0,0 @@ -/* Blink without Delay - due led - - Turns on and off a light emitting diode(LED) connected to a digital - pin, without using the delay() function. This means that other code - can run at the same time without being interrupted by the LED code. - - The circuit: - * LED attached from pin 13 to ground. - * Note: on most Arduinos, there is already an LED on the board - that's attached to pin 13, so no hardware is needed for this example. - - - created 2005 - by David A. Mellis - modified 8 Feb 2010 - by Paul Stoffregen - modified by eaman - - This example code is in the public domain. - - - http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay - */ - -// constants won't change. Used here to -// set pin numbers: -const int ledA = 13; // Primo LED -const int ledB = 12; // Secondo LED - -// Variabbili di stato -int ledStateA = LOW; // ledState used to set the LED -int ledStateB = LOW; // ledState used to set the LED - -long previousMillisA = 0; // will store last time LED was updated -long previousMillisB = 0; // will store last time LED was updated - -// the follow variables is a long because the time, measured in miliseconds, -// will quickly become a bigger number than can be stored in an int. -long intervalA = 1000; // interval at which to blink (milliseconds) -long intervalB = 500; // interval at which to blink (milliseconds) - -void setup() { - // set the digital pin as output: - pinMode(ledA, OUTPUT); - pinMode(ledB, OUTPUT); -} - -void loop() -{ -// Primo LED - if (millis() > previousMillisA + intervalA) { - // save the last time you blinked the LED - previousMillisA = millis(); - - // if the LED is off turn it on and vice-versa: - if (ledStateA == LOW) - ledStateA = HIGH; - else - ledStateA = LOW; - // set the LED with the ledState of the variable: - digitalWrite(ledA, ledStateA); - } - -// Secondo LED - if (millis() > previousMillisB + intervalB) { - // save the last time you blinked the LED - previousMillisB = millis(); - - // if the LED is off turn it on and vice-versa: - if (ledStateB == LOW) - ledStateB = HIGH; - else - ledStateB = LOW; - // set the LED with the ledState of the variable: - digitalWrite(ledB, ledStateB); - } -} - -/* Domande - 1. Provare a isolare il codice per accendere ogni singolo led in una funzione: - - Quali variabili determinano il comportamento del LED? - - Come cambiano durante il corso dello script? - - Sono globali o locali? - - Quali parti vanno eseguite una sola volta e quali a ogni esecuzione? - */ - - - diff --git a/oggi/BlinkWithoutDelay_2_led_cleanup/BlinkWithoutDelay_2_led_cleanup.ino b/oggi/BlinkWithoutDelay_2_led_cleanup/BlinkWithoutDelay_2_led_cleanup.ino deleted file mode 100644 index 21c26eb..0000000 --- a/oggi/BlinkWithoutDelay_2_led_cleanup/BlinkWithoutDelay_2_led_cleanup.ino +++ /dev/null @@ -1,77 +0,0 @@ -/* Blink without Delay - due led - - Turns on and off a light emitting diode(LED) connected to a digital - pin, without using the delay() function. This means that other code - can run at the same time without being interrupted by the LED code. - - The circuit: - * LED attached from pin 13 to ground. - * Note: on most Arduinos, there is already an LED on the board - that's attached to pin 13, so no hardware is needed for this example. - - - created 2005 - by David A. Mellis - modified 8 Feb 2010 - by Paul Stoffregen - modified by eaman - - This example code is in the public domain. - - - http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay - */ - -// constants won't change. Used here to -// set pin numbers: -const int ledA = 13; // Primo LED -const int ledB = 12; // Secondo LED - -// Variabbili di stato -int ledStateA = LOW; // ledState used to set the LED -//int ledStateB = LOW; // Not used - -long previousMillisA = 0; // will store last time LED was updated -unsigned long previousMillisB = 0; // will store last time LED was updated - -// the follow variables is a long because the time, measured in miliseconds, -// will quickly become a bigger number than can be stored in an int. -long intervalA = 1000; // interval at which to blink (milliseconds) -long intervalB = 500; // interval at which to blink (milliseconds) - -void setup() { - // set the digital pin as output: - pinMode(ledA, OUTPUT); - pinMode(ledB, OUTPUT); -} - -void loop() -{ -// Primo LED - if (millis() - previousMillisA > intervalA) { - // save the last time you blinked the LED - previousMillisA = millis(); - - // if the LED is off turn it on and vice-versa: - ledStateA = !ledStateA; - // set the LED with the ledState of the variable: - digitalWrite(ledA, ledStateA); - } - -// Secondo LED: contratta - if (millis() - previousMillisB > intervalB) { - digitalWrite(ledB, !digitalRead(ledB)); - previousMillisB = millis(); - } -} - -/* Domande - 1. Provare a isolare il codice per accendere ogni singolo led in una funzione: - - Quali variabili determinano il comportamento del LED? - - Come cambiano durante il corso dello script? - - Sono globali o locali? - - Quali parti vanno eseguite una sola volta e quali a ogni esecuzione? - */ - - - diff --git a/oggi/blink_0/blink_0.ino b/oggi/blink_0/blink_0.ino deleted file mode 100644 index 1b7c15b..0000000 --- a/oggi/blink_0/blink_0.ino +++ /dev/null @@ -1,29 +0,0 @@ -/* - Blink v1 - - Accensione e spegnimanto di un LED utilizzando variabili - per impostare la velocita' del lampeggio. - - */ - -// Pin 13 ha un LED collegato di default -int led = 13; - -void setup() { - // Inizializziamo il PIN 13 come OUTPUT - pinMode(led, OUTPUT); -} - -void loop() { - digitalWrite(led, HIGH); - delay(1000); - digitalWrite(led, LOW); - delay(1000); -} - -/* Domande - 1. Aggiungere un secondo LED e farlo brillare ogni 500ms - mentre il primo brilla ogni 1000ms - 2. Cosa succederebbe se dovessi anche leggere un input da un sensore / bottone? - */ - diff --git a/oggi/blink_0_soluzione/blink_0_soluzione.ino b/oggi/blink_0_soluzione/blink_0_soluzione.ino deleted file mode 100644 index 8c302d9..0000000 --- a/oggi/blink_0_soluzione/blink_0_soluzione.ino +++ /dev/null @@ -1,81 +0,0 @@ -/* - Blink due LED - Soluzione - - Aggiungere un secondo LED e farlo brillare ogni 500ms - mentre il primo brilla ogni 1000ms - - Massimo comun denominatore 1000 MCD 500 = 500ms - Durata Periodo = 500ms - - - Stati: - - a | b Changes - ======== ========= - 1 | 1 x | x - 1 | 0 | x - 0 | 1 x | x - 0 | 0 | x - - - */ - -// Pin 13 has an LED connected on most Arduino boards. -// give it a name: -const int ledA = 13; //Primo LED -const int ledB = 12; //Secondo LED, con resistenza - -// the setup routine runs once when you press reset: -void setup() { - // initialize the digital pin as an output. - pinMode(ledA, OUTPUT); - pinMode(ledB, OUTPUT); -} - -// the loop routine runs over and over again forever: -void loop() { - // Primo periodo - digitalWrite(ledA, HIGH); // turn the LED on (HIGH is the voltage level) - digitalWrite(ledB, HIGH); - delay(500); // Minimo comun denominatore del periodo - - // Secondo periodo - //digitalWrite(ledA, HIGH); // ledA non cambia - digitalWrite(ledB, LOW); - delay(500); - - // Terzo periodo - digitalWrite(ledA, LOW); - digitalWrite(ledB, HIGH); - delay(500); - - // Quarto periodo - //digitalWrite(ledA, LOW); - digitalWrite(ledB, LOW); - delay(500); -} - -/* Domande - 1. Altro scenartio: fare brillare un LED ogni 300ms mentre il secondo brilla ogni 400m - 2. ...valutare come aggiungere un terzo LED, gestire altri intevalli. - */ - - - - - - - - - - - - - - - - - - - - diff --git a/programming/data_types_bin_hex_transformation_serial/data_types_bin_hex_transformation_serial.ino b/programming/data_types_bin_hex_transformation_serial/data_types_bin_hex_transformation_serial.ino deleted file mode 100644 index a02701e..0000000 --- a/programming/data_types_bin_hex_transformation_serial/data_types_bin_hex_transformation_serial.ino +++ /dev/null @@ -1,40 +0,0 @@ -void setup() { - // put your setup code here, to run once: - Serial.begin(9600); - -} - -void loop() { - - transforma(5); // Leggete i risultati con [CTR]+[SHIFT]+M - transforma(255); - - Serial.flush() ; - exit(0); // Termina l'esecuzione -} - -// Ignorate pure il resto del listato! - -/* Transforma - - Scrive su seriale il valore della variabile a - trasformandolo in binario e esadecimale - */ - -void transforma(int var) { - Serial.print("Valore in decimanle = "); - Serial.println(var); // Serial.println(a, DEC); - - Serial.print("Valore in binario = "); - Serial.println(var,BIN); - - Serial.print("Valore in esadecimanle = "); - Serial.println(var,HEX); - - Serial.println(); -} - - - - - diff --git a/programming/functions/argomenti_2/argomenti_2.ino b/programming/funzioni/argomenti_2/argomenti_2.ino similarity index 70% rename from programming/functions/argomenti_2/argomenti_2.ino rename to programming/funzioni/argomenti_2/argomenti_2.ino index 9be5904..b5136b7 100644 --- a/programming/functions/argomenti_2/argomenti_2.ino +++ b/programming/funzioni/argomenti_2/argomenti_2.ino @@ -1,3 +1,10 @@ +/* +Fuznioni: return + +La funzione area accetta due parametri di tipo int +e ritorna un int corrispondente all'area. +*/ + void setup(){ Serial.begin(9600); } diff --git a/programming/blink_with_functions/blink_with_functions.ino b/programming/funzioni/blink_with_functions/blink_with_functions.ino similarity index 86% rename from programming/blink_with_functions/blink_with_functions.ino rename to programming/funzioni/blink_with_functions/blink_with_functions.ino index 3d8a6a9..f1bddf5 100644 --- a/programming/blink_with_functions/blink_with_functions.ino +++ b/programming/funzioni/blink_with_functions/blink_with_functions.ino @@ -3,7 +3,7 @@ Le funzioni sono una sequenza di istruzione raggruppate appunto in un a funzione. Le funzioni possono accettare argomenti e avere questi pre-impostati a valori di default se omessi. - Le funzioni possono limitarsi a svolgere istruzionioppure elaborare valori restituendo un risultato. + Le funzioni possono limitarsi a svolgere istruzioni oppure elaborare valori restituendo un risultato. */ diff --git a/programming/blink_with_functions/funzioni.ino b/programming/funzioni/blink_with_functions/funzioni.ino similarity index 100% rename from programming/blink_with_functions/funzioni.ino rename to programming/funzioni/blink_with_functions/funzioni.ino diff --git a/programming/functions/scope_1/scope_1.ino b/programming/funzioni/scope_1/scope_1.ino similarity index 100% rename from programming/functions/scope_1/scope_1.ino rename to programming/funzioni/scope_1/scope_1.ino diff --git a/programming/conditional_test/head_tails_ino/head_tails_ino.ino b/programming/head_tails_ino/head_tails_ino.ino similarity index 96% rename from programming/conditional_test/head_tails_ino/head_tails_ino.ino rename to programming/head_tails_ino/head_tails_ino.ino index 7587967..7102f13 100644 --- a/programming/conditional_test/head_tails_ino/head_tails_ino.ino +++ b/programming/head_tails_ino/head_tails_ino.ino @@ -11,7 +11,7 @@ // Pin 13 has an LED connected on most Arduino boards. // give it a name: const int head = 13 ; // LED for HEAD -const int tail = 12 ; // LEAD for Tails +const int tail = 12 ; // LED for Tails const int PAUSE = 1000 ; const int REST = 50 ; long randomNumber = 0L; // Use the "L" to tell compiler it's a long data type, not an int. @@ -44,9 +44,7 @@ void loop() { tCount++ ; } - delay(PAUSE); // Long pause - runs++; - + // Serial output if (runs % 10 == 0) { // Each 10 runs print a summary to serial Serial.print("Results after more 10 runs, for a total of: "); Serial.println(runs); @@ -55,6 +53,10 @@ void loop() { Serial.print("Heads: \t"); Serial.println(hCount); } + + delay(PAUSE); // Long pause + runs++; + } diff --git a/programming/leap_year_functions/leap_year_functions.ino b/programming/leap_year_functions/leap_year_functions.ino deleted file mode 100644 index befac46..0000000 --- a/programming/leap_year_functions/leap_year_functions.ino +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Program: find out is the user typed in a leap year. The code assumes - * the user is not an idiot and only types in numbers that are a valid - * year. - * Author: Dr. Purdum, Aug. 7, 2012 - **/ -void setup() -{ - Serial.begin(9600); -} -void loop() -{ - if (Serial.available() > 0) { - int bufferCount; - int year; - char myData[20]; - bufferCount = ReadLine(myData); - year = atoi(myData); - Serial.print("Year: "); - Serial.print(year); - if (IsLeapYear(year)) { - Serial.print(" is "); - } - else { - Serial.print(" is not "); - } - Serial.println("a leap year"); - } -} -// Convert to int -/***** - * Purpose: Determine if a given year is a leap year - * Parameters: - * int yr - * The year to test - * Return value: - * int - * 1 if the year is a leap year, 0 otherwise - *****/ -int IsLeapYear(int yr) -{ - if (yr % 4 == 0 && yr % 100 != 0 || yr % 400 == 0) { - return 1; // It is a leap year - } - else { - return 0; - // not a leap year - } -} -/***** - * Purpose: Read data from serial port until a newline character is read ('\n') - * Parameters: - * char str[] - * character array that will be treated as a nul-terminated string - * Return value: - * int - * the number of characters read for the string - * CAUTION: This method will sit here forever if no input is read from the serial - * port and no newline character is entered. - ****/ -int ReadLine(char str[]) -{ - char c; - int index = 0; - while (true) { - if (Serial.available() > 0) { - c = Serial.read(); - if (c != '\n') { - str[index++] = c; - } - else { - str[index] = '\0'; // null termination character - break; - } - } - } - return index; -} - - diff --git a/serial/README b/serial/README index 6e1c3f6..84b2911 100644 --- a/serial/README +++ b/serial/README @@ -1,3 +1,6 @@ +Esercizi sulle comunicazioni seriali +-------------------------------------- + - Simple serial communication 2 arduino: switch 1 and LED 2 - Serial Parser: Examples -> strings - Serial to RGB LED -- 2.39.2