From: eaman Date: Wed, 21 Dec 2016 11:25:48 +0000 (+0100) Subject: clean up X-Git-Url: http://git.piffa.net/web?p=sketchbook_andrea;a=commitdiff_plain;h=2e29cbe13965809a5d3866ccdc12b1d665b54115 clean up --- 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/advanced_projects/avr_greadboard/boards.txt b/advanced_projects/avr_greadboard/boards.txt new file mode 100644 index 0000000..abaf2b4 --- /dev/null +++ b/advanced_projects/avr_greadboard/boards.txt @@ -0,0 +1,24 @@ +############################################################## + +atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock) + +atmega328bb.upload.protocol=arduino +atmega328bb.upload.maximum_size=30720 +atmega328bb.upload.speed=57600 + +atmega328bb.bootloader.low_fuses=0xE2 +atmega328bb.bootloader.high_fuses=0xDA +atmega328bb.bootloader.extended_fuses=0x05 + +atmega328bb.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex +atmega328bb.bootloader.unlock_bits=0x3F +atmega328bb.bootloader.lock_bits=0x0F + +atmega328bb.build.mcu=atmega328p +atmega328bb.build.f_cpu=8000000L +atmega328bb.build.core=arduino:arduino +atmega328bb.build.variant=arduino:standard + + +atmega328bb.bootloader.tool=arduino:avrdude +atmega328bb.upload.tool=arduino:avrdude diff --git a/advanced_projects/avr_greadboard/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex b/advanced_projects/avr_greadboard/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex new file mode 100644 index 0000000..9753e2e --- /dev/null +++ b/advanced_projects/avr_greadboard/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex @@ -0,0 +1,124 @@ +:107800000C94343C0C94513C0C94513C0C94513CE1 +:107810000C94513C0C94513C0C94513C0C94513CB4 +:107820000C94513C0C94513C0C94513C0C94513CA4 +:107830000C94513C0C94513C0C94513C0C94513C94 +:107840000C94513C0C94513C0C94513C0C94513C84 +:107850000C94513C0C94513C0C94513C0C94513C74 +:107860000C94513C0C94513C11241FBECFEFD8E036 +:10787000DEBFCDBF11E0A0E0B1E0EAE8FFE702C063 +:1078800005900D92A230B107D9F712E0A2E0B1E065 +:1078900001C01D92AD30B107E1F70E942D3D0C945F +:1078A000C33F0C94003C982F95959595959595958B +:1078B000905D8F708A307CF0282F295A8091C0000B +:1078C00085FFFCCF9093C6008091C00085FFFCCF60 +:1078D0002093C6000895282F205DF0CF982F809127 +:1078E000C00085FFFCCF9093C6000895EF92FF92F1 +:1078F0000F931F93EE24FF2487018091C00087FD22 +:1079000017C00894E11CF11C011D111D81E2E8164D +:1079100081EAF80687E0080780E0180770F3E09135 +:107920000401F091050109958091C00087FFE9CF1E +:107930008091C6001F910F91FF90EF9008950E94D3 +:10794000763C982F8091C00085FFFCCF9093C600B5 +:1079500091362CF490330CF09053892F089597555D +:10796000892F08951F930E949F3C182F0E949F3CCF +:107970001295107F810F1F9108951F93182F882350 +:1079800021F00E94763C1150E1F71F9108951F935A +:10799000182F0E94763C803249F0809103018F5F5E +:1079A000809303018530C1F01F9108958091C0003C +:1079B00085FFFCCF84E18093C6008091C00085FFE5 +:1079C000FCCF1093C6008091C00085FFFCCF80E102 +:1079D0008093C6001F910895E0910401F091050184 +:1079E00009951F9108950E94763C803241F0809164 +:1079F00003018F5F80930301853081F008958091AA +:107A0000C00085FFFCCF84E18093C6008091C00058 +:107A100085FFFCCF80E18093C6000895E0910401CA +:107A2000F09105010995089548EC50E08823A1F0F4 +:107A30002D9A28EE33E0FA013197F1F721503040CA +:107A4000D1F72D9828EE33E0FA013197F1F7215064 +:107A50003040D1F7815061F708953F924F925F9285 +:107A60006F927F928F929F92AF92BF92CF92DF924E +:107A7000EF92FF920F931F93CF93DF93000082E06A +:107A80008093C00080E18093C4001092C50088E11B +:107A90008093C10086E08093C2005098589A259A3E +:107AA00081E00E94143D24E1F22E9EE1E92E85E959 +:107AB000D82E0FE0C02E10E1B12EAA24A394B1E479 +:107AC0009B2EA6E58A2EF2E57F2EE0E26E2E79E46B +:107AD000572E63E5462E50E5352E0E94763C8033C6 +:107AE000B1F18133B9F1803409F46FC0813409F404 +:107AF00076C0823409F485C0853409F488C08035A5 +:107B000031F1823521F1813511F1853509F485C0D6 +:107B1000863509F48DC0843609F496C0843709F49B +:107B200003C1853709F472C1863709F466C08091B4 +:107B300003018F5F80930301853079F6E0910401A2 +:107B4000F091050109950E94763C803351F60E9420 +:107B5000F33CC3CF0E94763C803249F78091C0004D +:107B600085FFFCCFF092C6008091C00085FFFCCF5E +:107B70009092C6008091C00085FFFCCF8092C60025 +:107B80008091C00085FFFCCF7092C6008091C0003C +:107B900085FFFCCF6092C6008091C00085FFFCCFBE +:107BA0005092C6008091C00085FFFCCF4092C60075 +:107BB0008091C00085FFFCCF3092C6008091C0004C +:107BC00085FFFCCFB092C60088CF0E94763C8638F5 +:107BD00008F4BDCF0E94763C0E94F33C7ECF0E9409 +:107BE000763C803809F49CC0813809F40BC1823896 +:107BF00009F430C1883909F48FC080E00E94C73C85 +:107C00006CCF84E10E94BD3C0E94F33C66CF85E0CE +:107C10000E94BD3C0E94F33C60CF0E94763C809362 +:107C200006010E94763C809307010E94F33C55CFE9 +:107C30000E94763C803309F411C183E00E94BD3C70 +:107C400080E00E94C73C49CF0E94763C80930902A5 +:107C50000E94763C8093080280910C028E7F809374 +:107C60000C020E94763C853409F409C18091080217 +:107C700090910902892B89F000E010E00E94763C87 +:107C8000F801E85FFE4F80830F5F1F4F809108026D +:107C9000909109020817190788F30E94763C8032F8 +:107CA00009F045CF80910C0280FFF5C0609106017C +:107CB00070910701660F771F7093070160930601AB +:107CC000A0910802B09109021097C9F0E8E0F1E034 +:107CD0009B01AD014E0F5F1FF999FECF32BD21BD53 +:107CE000819180BDFA9AF99A2F5F3F4FE417F5070B +:107CF00099F76A0F7B1F70930701609306018091CB +:107D0000C00085FFFCCFF092C6008091C00085FFC7 +:107D1000FCCFB092C600E1CE83E00E94C73CDDCE2E +:107D200082E00E94C73CD9CE0E94763C8093090233 +:107D30000E94763C80930802809106019091070191 +:107D4000880F991F90930701809306010E94763C4B +:107D5000853409F49AC080910C028E7F80930C02C6 +:107D60000E94763C803209F0B8CE8091C00085FF39 +:107D7000FCCFF092C600A0910802B09109021097C2 +:107D8000C1F180910C02082F0170182F1695117007 +:107D9000E0910601F0910701AF014F5F5F4FBA011B +:107DA00020E030E00023B1F4112339F49491809164 +:107DB000C00085FFFCCF9093C6002F5F3F4FCB01E3 +:107DC0000196FA012A173B0780F4BC014F5F5F4F11 +:107DD000002351F3F999FECFF2BDE1BDF89A90B5B9 +:107DE0008091C00085FFFCCFE6CF709307016093C0 +:107DF00006018091C00085FDE5CE8091C00085FF21 +:107E0000F8CFE0CE81E00E94C73C67CE0E94763C6E +:107E1000803209F08CCE8091C00085FFFCCFF092BB +:107E2000C6008091C00085FFFCCFE092C600809123 +:107E3000C00085FFFCCFD092C6008091C00085FFB6 +:107E4000FCCFC092C6008091C00085FFFCCFB092ED +:107E5000C60043CE80E10E94C73C3FCE0E94763CE4 +:107E60000E94763C182F0E94763C112309F483C0AF +:107E7000113009F484C08FE00E94C73C2ECE80915F +:107E80000C02816080930C02F1CE80910C02816023 +:107E900080930C0265CF809107018823880F880B9F +:107EA0008A2180930B028091060190910701880F2F +:107EB000991F90930701809306018091080280FF2B +:107EC00009C08091080290910902019690930902DD +:107ED00080930802F894F999FECF1127E0910601EA +:107EE000F0910701C8E0D1E0809108029091090269 +:107EF000103091F40091570001700130D9F303E084 +:107F000000935700E8950091570001700130D9F3B4 +:107F100001E100935700E8950990199000915700EE +:107F200001700130D9F301E000935700E8951395F3 +:107F3000103498F011270091570001700130D9F3E7 +:107F400005E000935700E89500915700017001305B +:107F5000D9F301E100935700E8953296029709F0B2 +:107F6000C7CF103011F00296E5CF11248091C000E8 +:107F700085FFC5CEC8CE8EE10E94C73CAECD85E957 +:0A7F80000E94C73CAACDF894FFCF81 +:027F8A00800075 +:040000030000780081 +:00000001FF diff --git a/breadboard/avr/boards.txt b/breadboard/avr/boards.txt deleted file mode 100644 index abaf2b4..0000000 --- a/breadboard/avr/boards.txt +++ /dev/null @@ -1,24 +0,0 @@ -############################################################## - -atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock) - -atmega328bb.upload.protocol=arduino -atmega328bb.upload.maximum_size=30720 -atmega328bb.upload.speed=57600 - -atmega328bb.bootloader.low_fuses=0xE2 -atmega328bb.bootloader.high_fuses=0xDA -atmega328bb.bootloader.extended_fuses=0x05 - -atmega328bb.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex -atmega328bb.bootloader.unlock_bits=0x3F -atmega328bb.bootloader.lock_bits=0x0F - -atmega328bb.build.mcu=atmega328p -atmega328bb.build.f_cpu=8000000L -atmega328bb.build.core=arduino:arduino -atmega328bb.build.variant=arduino:standard - - -atmega328bb.bootloader.tool=arduino:avrdude -atmega328bb.upload.tool=arduino:avrdude diff --git a/breadboard/avr/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex b/breadboard/avr/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex deleted file mode 100644 index 9753e2e..0000000 --- a/breadboard/avr/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex +++ /dev/null @@ -1,124 +0,0 @@ -:107800000C94343C0C94513C0C94513C0C94513CE1 -:107810000C94513C0C94513C0C94513C0C94513CB4 -:107820000C94513C0C94513C0C94513C0C94513CA4 -:107830000C94513C0C94513C0C94513C0C94513C94 -:107840000C94513C0C94513C0C94513C0C94513C84 -:107850000C94513C0C94513C0C94513C0C94513C74 -:107860000C94513C0C94513C11241FBECFEFD8E036 -:10787000DEBFCDBF11E0A0E0B1E0EAE8FFE702C063 -:1078800005900D92A230B107D9F712E0A2E0B1E065 -:1078900001C01D92AD30B107E1F70E942D3D0C945F -:1078A000C33F0C94003C982F95959595959595958B -:1078B000905D8F708A307CF0282F295A8091C0000B -:1078C00085FFFCCF9093C6008091C00085FFFCCF60 -:1078D0002093C6000895282F205DF0CF982F809127 -:1078E000C00085FFFCCF9093C6000895EF92FF92F1 -:1078F0000F931F93EE24FF2487018091C00087FD22 -:1079000017C00894E11CF11C011D111D81E2E8164D -:1079100081EAF80687E0080780E0180770F3E09135 -:107920000401F091050109958091C00087FFE9CF1E -:107930008091C6001F910F91FF90EF9008950E94D3 -:10794000763C982F8091C00085FFFCCF9093C600B5 -:1079500091362CF490330CF09053892F089597555D -:10796000892F08951F930E949F3C182F0E949F3CCF -:107970001295107F810F1F9108951F93182F882350 -:1079800021F00E94763C1150E1F71F9108951F935A -:10799000182F0E94763C803249F0809103018F5F5E -:1079A000809303018530C1F01F9108958091C0003C -:1079B00085FFFCCF84E18093C6008091C00085FFE5 -:1079C000FCCF1093C6008091C00085FFFCCF80E102 -:1079D0008093C6001F910895E0910401F091050184 -:1079E00009951F9108950E94763C803241F0809164 -:1079F00003018F5F80930301853081F008958091AA -:107A0000C00085FFFCCF84E18093C6008091C00058 -:107A100085FFFCCF80E18093C6000895E0910401CA -:107A2000F09105010995089548EC50E08823A1F0F4 -:107A30002D9A28EE33E0FA013197F1F721503040CA -:107A4000D1F72D9828EE33E0FA013197F1F7215064 -:107A50003040D1F7815061F708953F924F925F9285 -:107A60006F927F928F929F92AF92BF92CF92DF924E -:107A7000EF92FF920F931F93CF93DF93000082E06A -:107A80008093C00080E18093C4001092C50088E11B -:107A90008093C10086E08093C2005098589A259A3E -:107AA00081E00E94143D24E1F22E9EE1E92E85E959 -:107AB000D82E0FE0C02E10E1B12EAA24A394B1E479 -:107AC0009B2EA6E58A2EF2E57F2EE0E26E2E79E46B -:107AD000572E63E5462E50E5352E0E94763C8033C6 -:107AE000B1F18133B9F1803409F46FC0813409F404 -:107AF00076C0823409F485C0853409F488C08035A5 -:107B000031F1823521F1813511F1853509F485C0D6 -:107B1000863509F48DC0843609F496C0843709F49B -:107B200003C1853709F472C1863709F466C08091B4 -:107B300003018F5F80930301853079F6E0910401A2 -:107B4000F091050109950E94763C803351F60E9420 -:107B5000F33CC3CF0E94763C803249F78091C0004D -:107B600085FFFCCFF092C6008091C00085FFFCCF5E -:107B70009092C6008091C00085FFFCCF8092C60025 -:107B80008091C00085FFFCCF7092C6008091C0003C -:107B900085FFFCCF6092C6008091C00085FFFCCFBE -:107BA0005092C6008091C00085FFFCCF4092C60075 -:107BB0008091C00085FFFCCF3092C6008091C0004C -:107BC00085FFFCCFB092C60088CF0E94763C8638F5 -:107BD00008F4BDCF0E94763C0E94F33C7ECF0E9409 -:107BE000763C803809F49CC0813809F40BC1823896 -:107BF00009F430C1883909F48FC080E00E94C73C85 -:107C00006CCF84E10E94BD3C0E94F33C66CF85E0CE -:107C10000E94BD3C0E94F33C60CF0E94763C809362 -:107C200006010E94763C809307010E94F33C55CFE9 -:107C30000E94763C803309F411C183E00E94BD3C70 -:107C400080E00E94C73C49CF0E94763C80930902A5 -:107C50000E94763C8093080280910C028E7F809374 -:107C60000C020E94763C853409F409C18091080217 -:107C700090910902892B89F000E010E00E94763C87 -:107C8000F801E85FFE4F80830F5F1F4F809108026D -:107C9000909109020817190788F30E94763C8032F8 -:107CA00009F045CF80910C0280FFF5C0609106017C -:107CB00070910701660F771F7093070160930601AB -:107CC000A0910802B09109021097C9F0E8E0F1E034 -:107CD0009B01AD014E0F5F1FF999FECF32BD21BD53 -:107CE000819180BDFA9AF99A2F5F3F4FE417F5070B -:107CF00099F76A0F7B1F70930701609306018091CB -:107D0000C00085FFFCCFF092C6008091C00085FFC7 -:107D1000FCCFB092C600E1CE83E00E94C73CDDCE2E -:107D200082E00E94C73CD9CE0E94763C8093090233 -:107D30000E94763C80930802809106019091070191 -:107D4000880F991F90930701809306010E94763C4B -:107D5000853409F49AC080910C028E7F80930C02C6 -:107D60000E94763C803209F0B8CE8091C00085FF39 -:107D7000FCCFF092C600A0910802B09109021097C2 -:107D8000C1F180910C02082F0170182F1695117007 -:107D9000E0910601F0910701AF014F5F5F4FBA011B -:107DA00020E030E00023B1F4112339F49491809164 -:107DB000C00085FFFCCF9093C6002F5F3F4FCB01E3 -:107DC0000196FA012A173B0780F4BC014F5F5F4F11 -:107DD000002351F3F999FECFF2BDE1BDF89A90B5B9 -:107DE0008091C00085FFFCCFE6CF709307016093C0 -:107DF00006018091C00085FDE5CE8091C00085FF21 -:107E0000F8CFE0CE81E00E94C73C67CE0E94763C6E -:107E1000803209F08CCE8091C00085FFFCCFF092BB -:107E2000C6008091C00085FFFCCFE092C600809123 -:107E3000C00085FFFCCFD092C6008091C00085FFB6 -:107E4000FCCFC092C6008091C00085FFFCCFB092ED -:107E5000C60043CE80E10E94C73C3FCE0E94763CE4 -:107E60000E94763C182F0E94763C112309F483C0AF -:107E7000113009F484C08FE00E94C73C2ECE80915F -:107E80000C02816080930C02F1CE80910C02816023 -:107E900080930C0265CF809107018823880F880B9F -:107EA0008A2180930B028091060190910701880F2F -:107EB000991F90930701809306018091080280FF2B -:107EC00009C08091080290910902019690930902DD -:107ED00080930802F894F999FECF1127E0910601EA -:107EE000F0910701C8E0D1E0809108029091090269 -:107EF000103091F40091570001700130D9F303E084 -:107F000000935700E8950091570001700130D9F3B4 -:107F100001E100935700E8950990199000915700EE -:107F200001700130D9F301E000935700E8951395F3 -:107F3000103498F011270091570001700130D9F3E7 -:107F400005E000935700E89500915700017001305B -:107F5000D9F301E100935700E8953296029709F0B2 -:107F6000C7CF103011F00296E5CF11248091C000E8 -:107F700085FFC5CEC8CE8EE10E94C73CAECD85E957 -:0A7F80000E94C73CAACDF894FFCF81 -:027F8A00800075 -:040000030000780081 -:00000001FF diff --git a/hardware/shift_register/shiftOut_binary_count/shiftOut_binary_count.ino b/hardware/shift_register/shiftOut_binary_count/shiftOut_binary_count.ino new file mode 100644 index 0000000..5ac868c --- /dev/null +++ b/hardware/shift_register/shiftOut_binary_count/shiftOut_binary_count.ino @@ -0,0 +1,57 @@ + +//**************************************************************// +// Name : shiftOutCode, Hello World +// Author : Carlyn Maw,Tom Igoe, David A. Mellis +// Date : 25 Oct, 2006 +// Modified: 23 Mar 2010 +// Version : 2.0 +// Notes : Code for using a 74HC595 Shift Register // +// : to count from 0 to 255 +//**************************************************************** + +//Pin connected to ST_CP of 74HC595 +int latchPin = 8; +//Pin connected to SH_CP of 74HC595 +int clockPin = 12; +////Pin connected to DS of 74HC595 +int dataPin = 11; + + + +void setup() { + //set pins to output so you can control the shift register + pinMode(latchPin, OUTPUT); + pinMode(clockPin, OUTPUT); + pinMode(dataPin, OUTPUT); + // Serial Debug + Serial.begin(9600); + Serial.print("Decimal"); + Serial.print("\t"); + Serial.println("Binary"); +} + +void loop() { + // count from 0 to 255 and display the number + // on the LEDs + for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) { + // take the latchPin low so + // the LEDs don't change while you're sending in bits: + digitalWrite(latchPin, LOW); + + // shift out the bits: + shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay); + + //take the latch pin high so the LEDs will light up: + digitalWrite(latchPin, HIGH); + // Serial Debug + Serial.print(numberToDisplay); + Serial.print("\t"); + Serial.println(numberToDisplay, BIN); + // pause before next value: + delay(200); + } +} + + + + diff --git a/hardware/shift_register/shift_register_8bit/shift_register_8bit.ino b/hardware/shift_register/shift_register_8bit/shift_register_8bit.ino new file mode 100644 index 0000000..7ce253e --- /dev/null +++ b/hardware/shift_register/shift_register_8bit/shift_register_8bit.ino @@ -0,0 +1,43 @@ +//**************************************************************// +// Name : shiftOutCode, Hello World +// Author : Carlyn Maw,Tom Igoe, David A. Mellis +// Date : 25 Oct, 2006 +// Modified: 23 Mar 2010 +// Version : 2.0 +// Notes : Code for using a 74HC595 Shift Register +// +// : to count from 0 to 255 +//**************************************************************** + + +//Pin connected to ST_CP of 74HC595 +int latchPin = 8; +//Pin connected to SH_CP of 74HC595 +int clockPin = 12; +////Pin connected to DS of 74HC595 +int dataPin = 11; +void setup() { + //set pins to output so you can control the shift register + pinMode(latchPin, OUTPUT); + +pinMode(clockPin, OUTPUT); +pinMode(dataPin, OUTPUT); +} +void loop() { + // count from 0 to 255 and display the number + // on the LEDs + for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) { + // take the latchPin low so + // the LEDs don’t change while you’re sending in bits: + digitalWrite(latchPin, LOW); + // shift out the bits: + shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay); + //take the latch pin high so the LEDs will light up: + digitalWrite(latchPin, HIGH); + // pause before next value: + delay(500); + } +} + + + diff --git a/hardware/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 new file mode 100644 index 0000000..c5e1da7 --- /dev/null +++ b/hardware/shift_register/shift_register_custom_pattern_4/shift_register_custom_pattern_4.ino @@ -0,0 +1,136 @@ + +/* + Shift Register Example + Turning on the outputs of a 74HC595 using an array + + Hardware: + * 74HC595 shift register + * LEDs attached to each of the outputs of the shift register + + */ +//Pin connected to ST_CP of 74HC595 +int latchPin = 8; +//Pin connected to SH_CP of 74HC595 +int clockPin = 12; +////Pin connected to DS of 74HC595 +int dataPin = 11; + +//holders for infromation you're going to pass to shifting function +byte data; +byte dataArray[10]; + +void setup() { + //set pins to output because they are addressed in the main loop + pinMode(latchPin, OUTPUT); + Serial.begin(9600); + + //Arduino doesn't seem to have a way to write binary straight into the code + //so these values are in HEX. Decimal would have been fine, too. + dataArray[0] = 0xFF; //11111111 + dataArray[1] = 0xFE; //11111110 + dataArray[2] = 0xFC; //11111100 + dataArray[3] = 0xF8; //11111000 + dataArray[4] = 0xF0; //11110000 + dataArray[5] = 0xE0; //11100000 + dataArray[6] = 0xC0; //11000000 + dataArray[7] = 0x80; //10000000 + dataArray[8] = 0x00; //00000000 + dataArray[9] = 0x38; //11100000 + + //function that blinks all the LEDs + //gets passed the number of blinks and the pause time + blinkAll_2Bytes(2,500); +} + +void loop() { + + for (int j = 0; j < 10; j++) { + //load the light sequence you want from array + data = dataArray[j]; + //ground latchPin and hold low for as long as you are transmitting + digitalWrite(latchPin, 0); + //move 'em out + shiftOut(dataPin, clockPin, data); + //return the latch pin high to signal chip that it + //no longer needs to listen for information + digitalWrite(latchPin, 1); + delay(300); + } +} + + + +// the heart of the program +void shiftOut(int myDataPin, int myClockPin, byte myDataOut) { + // This shifts 8 bits out MSB first, + //on the rising edge of the clock, + //clock idles low + + //internal function setup + int i=0; + int pinState; + pinMode(myClockPin, OUTPUT); + pinMode(myDataPin, OUTPUT); + + //clear everything out just in case to + //prepare shift register for bit shifting + digitalWrite(myDataPin, 0); + digitalWrite(myClockPin, 0); + + //for each bit in the byte myDataOut� + //NOTICE THAT WE ARE COUNTING DOWN in our for loop + //This means that %00000001 or "1" will go through such + //that it will be pin Q0 that lights. + for (i=7; i>=0; i--) { + digitalWrite(myClockPin, 0); + + //if the value passed to myDataOut and a bitmask result + // true then... so if we are at i=6 and our value is + // %11010100 it would the code compares it to %01000000 + // and proceeds to set pinState to 1. + if ( myDataOut & (1<= count){ + index = 0; + } +} + diff --git a/hardware/shift_register/shift_register_pattern/sketch_jan27c/sketch_jan27c.ino b/hardware/shift_register/shift_register_pattern/sketch_jan27c/sketch_jan27c.ino new file mode 100644 index 0000000..c5e1da7 --- /dev/null +++ b/hardware/shift_register/shift_register_pattern/sketch_jan27c/sketch_jan27c.ino @@ -0,0 +1,136 @@ + +/* + Shift Register Example + Turning on the outputs of a 74HC595 using an array + + Hardware: + * 74HC595 shift register + * LEDs attached to each of the outputs of the shift register + + */ +//Pin connected to ST_CP of 74HC595 +int latchPin = 8; +//Pin connected to SH_CP of 74HC595 +int clockPin = 12; +////Pin connected to DS of 74HC595 +int dataPin = 11; + +//holders for infromation you're going to pass to shifting function +byte data; +byte dataArray[10]; + +void setup() { + //set pins to output because they are addressed in the main loop + pinMode(latchPin, OUTPUT); + Serial.begin(9600); + + //Arduino doesn't seem to have a way to write binary straight into the code + //so these values are in HEX. Decimal would have been fine, too. + dataArray[0] = 0xFF; //11111111 + dataArray[1] = 0xFE; //11111110 + dataArray[2] = 0xFC; //11111100 + dataArray[3] = 0xF8; //11111000 + dataArray[4] = 0xF0; //11110000 + dataArray[5] = 0xE0; //11100000 + dataArray[6] = 0xC0; //11000000 + dataArray[7] = 0x80; //10000000 + dataArray[8] = 0x00; //00000000 + dataArray[9] = 0x38; //11100000 + + //function that blinks all the LEDs + //gets passed the number of blinks and the pause time + blinkAll_2Bytes(2,500); +} + +void loop() { + + for (int j = 0; j < 10; j++) { + //load the light sequence you want from array + data = dataArray[j]; + //ground latchPin and hold low for as long as you are transmitting + digitalWrite(latchPin, 0); + //move 'em out + shiftOut(dataPin, clockPin, data); + //return the latch pin high to signal chip that it + //no longer needs to listen for information + digitalWrite(latchPin, 1); + delay(300); + } +} + + + +// the heart of the program +void shiftOut(int myDataPin, int myClockPin, byte myDataOut) { + // This shifts 8 bits out MSB first, + //on the rising edge of the clock, + //clock idles low + + //internal function setup + int i=0; + int pinState; + pinMode(myClockPin, OUTPUT); + pinMode(myDataPin, OUTPUT); + + //clear everything out just in case to + //prepare shift register for bit shifting + digitalWrite(myDataPin, 0); + digitalWrite(myClockPin, 0); + + //for each bit in the byte myDataOut� + //NOTICE THAT WE ARE COUNTING DOWN in our for loop + //This means that %00000001 or "1" will go through such + //that it will be pin Q0 that lights. + for (i=7; i>=0; i--) { + digitalWrite(myClockPin, 0); + + //if the value passed to myDataOut and a bitmask result + // true then... so if we are at i=6 and our value is + // %11010100 it would the code compares it to %01000000 + // and proceeds to set pinState to 1. + if ( myDataOut & (1< 0) { + // ASCII '0' through '9' characters are + // represented by the values 48 through 57. + // so if the user types a number from 0 through 9 in ASCII, + // you can subtract 48 to get the actual value: + int bitToSet = Serial.read() - 48; + + // write to the shift register with the correct bit set high: + registerWrite(bitToSet, HIGH); + } +} + +// This method sends bits to the shift register: + +void registerWrite(int whichPin, int whichState) { +// the bits you want to send + byte bitsToSend = 0; + + // turn off the output so the pins don't light up + // while you're shifting bits: + digitalWrite(latchPin, LOW); + + // turn on the next highest bit in bitsToSend: + bitWrite(bitsToSend, whichPin, whichState); + + // shift the bits out: + shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend); + + // turn on the output so the LEDs can light up: + digitalWrite(latchPin, HIGH); + delay(300); + +} + 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/blink_with_functions/blink_with_functions.ino b/programming/blink_with_functions/blink_with_functions.ino deleted file mode 100644 index 3d8a6a9..0000000 --- a/programming/blink_with_functions/blink_with_functions.ino +++ /dev/null @@ -1,30 +0,0 @@ -/* - Blink con funzioni. - - 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. - - */ - -// Pin 13 has an LED connected on most Arduino boards. -// give it a name: -int led = 13; - - -// 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() { - lunga() ; - lunga() ; - breve(); - breve(); - varia(3000); -} - -// Funzioni personalizzate: nella scheda funzioni. diff --git a/programming/blink_with_functions/funzioni.ino b/programming/blink_with_functions/funzioni.ino deleted file mode 100644 index 25568f1..0000000 --- a/programming/blink_with_functions/funzioni.ino +++ /dev/null @@ -1,51 +0,0 @@ -// Funzioni personalizzate -// Un scheda e' un documento che viene concatenato allo sketch originale - -void lunga() { - // Blink con pausa lunga - - digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) - delay(1000); // wait for a second - digitalWrite(led, LOW); // turn the LED off by making the voltage LOW - delay(1000); // wait for a second -} - -void breve() { - // Blink con pausa breve - - digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) - delay(200); // wait for a second - digitalWrite(led, LOW); // turn the LED off by making the voltage LOW - delay(1000); // wait for a second -} - -void varia(int a = 300) { // Varia has a default value, the user can override it with an argument - // Lampeggia per un tempo impostato dall'utente, - // il default e' 300ms - - digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) - delay(a); // wait for a second - digitalWrite(led, LOW); // turn the LED off by making the voltage LOW - delay(a); // wait for a second - -} - -void lampeggia(int ripetizioni) { - // Accende un LED per un numero stabilito di volte - - // Questa funziona accetta un parametro: ripetizioni - int i = 0; - while (i < ripetizioni) { - rapido(); // accende e spegne rapidamente il LED - i = i + 1 ; // incrementa l'iteratore - // i++ ; // equivalente - } -} - -int area(int latoA, int latoB) { - // Calcola l'area di un rettangolo - // e ritorna il valore calcolato: questa funzione ha un valore di ritorno - // dichiarato come int - - return(latoA * latoB); -} diff --git a/programming/conditional_test/head_tails_ino/head_tails_ino.ino b/programming/conditional_test/head_tails_ino/head_tails_ino.ino deleted file mode 100644 index 7587967..0000000 --- a/programming/conditional_test/head_tails_ino/head_tails_ino.ino +++ /dev/null @@ -1,61 +0,0 @@ -/* - Head tails - Generates a random number in order to simulate a coin toss. - - - Phisical LEDS and serial debug. - - This example code is in the public domain. - */ - -// 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 PAUSE = 1000 ; -const int REST = 50 ; -long randomNumber = 0L; // Use the "L" to tell compiler it's a long data type, not an int. -int hCount = 0; -int tCount = 0; -int runs = 0 ; - -// the setup routine runs once when you press reset: -void setup() { - // initialize the digital pin as an output. - pinMode(head, OUTPUT); - pinMode(tail, OUTPUT); - randomSeed(analogRead(0)); // Random initializer - Serial.begin(9600); - Serial.println("Initializing random sequence, please wait for results."); -} - -// the loop routine runs over and over again forever: -void loop() { - randomNumber = random(); - digitalWrite(head, LOW); - digitalWrite(tail, LOW); - delay(REST); // wait a bit - if (randomNumber % 2 == 1) { - digitalWrite(head, HIGH);// turn the LED on ON - hCount++ ; - } - else { - digitalWrite(tail, HIGH);// turn the LED ON - tCount++ ; - } - - delay(PAUSE); // Long pause - runs++; - - 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); - Serial.print("Tails: \t") ; - Serial.println(tCount); - Serial.print("Heads: \t"); - Serial.println(hCount); - } -} - - - 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/functions/argomenti_2/argomenti_2.ino deleted file mode 100644 index 9be5904..0000000 --- a/programming/functions/argomenti_2/argomenti_2.ino +++ /dev/null @@ -1,23 +0,0 @@ -void setup(){ - Serial.begin(9600); -} - -void loop() { -int latoA = 4; -int latoB = 3 ; - -Serial.print("Area rettangolo = "); -Serial.println(calcolaArea(latoA, latoB)); - - -Serial.flush(); -exit(0); -} - -// Funzioni - -int calcolaArea(int a, int b){ - int area = a * b ; - return area; -} - diff --git a/programming/functions/scope_1/scope_1.ino b/programming/functions/scope_1/scope_1.ino deleted file mode 100644 index 8e52430..0000000 --- a/programming/functions/scope_1/scope_1.ino +++ /dev/null @@ -1,49 +0,0 @@ -/* - Scope - - Variabili globali e locali rispetto a una funzione - Le variabili dichiarate al di fuori di funzioni - sono globali e accessibili a tutti, - - Le variabili dichiarate all'interno di una funzione - sono locali e accessibili solo a questa, - */ - - -boolean sposato = 1 ; // Variabile globale -void setup(){ - Serial.begin(9600); -} - -void loop() { -Serial.print("In standard mode sposato = "); -Serial.println(sposato); - -Serial.print("In vacanza mode sposato = "); -Serial.println(inVacanza(sposato)); - -Serial.print("Tornato a casa sposato = "); -Serial.println(sposato); - -// Global -Serial.print("In vacanza global mode sposato = "); -Serial.println(inVacanzaG()); - -Serial.print("Stato di sposato = "); -Serial.println(sposato); - -// Termine programma -Serial.flush(); -exit(0); -} - -// Funzioni - -boolean inVacanza(boolean sposato){ // variabile locale - sposato = 0 ; - return sposato; -} -boolean inVacanzaG(){ - sposato = 0 ; // Variabile globale - return sposato; -} diff --git a/programming/funzioni/argomenti_2/argomenti_2.ino b/programming/funzioni/argomenti_2/argomenti_2.ino new file mode 100644 index 0000000..b5136b7 --- /dev/null +++ b/programming/funzioni/argomenti_2/argomenti_2.ino @@ -0,0 +1,30 @@ +/* +Fuznioni: return + +La funzione area accetta due parametri di tipo int +e ritorna un int corrispondente all'area. +*/ + +void setup(){ + Serial.begin(9600); +} + +void loop() { +int latoA = 4; +int latoB = 3 ; + +Serial.print("Area rettangolo = "); +Serial.println(calcolaArea(latoA, latoB)); + + +Serial.flush(); +exit(0); +} + +// Funzioni + +int calcolaArea(int a, int b){ + int area = a * b ; + return area; +} + diff --git a/programming/funzioni/blink_with_functions/blink_with_functions.ino b/programming/funzioni/blink_with_functions/blink_with_functions.ino new file mode 100644 index 0000000..f1bddf5 --- /dev/null +++ b/programming/funzioni/blink_with_functions/blink_with_functions.ino @@ -0,0 +1,30 @@ +/* + Blink con funzioni. + + 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 istruzioni oppure elaborare valori restituendo un risultato. + + */ + +// Pin 13 has an LED connected on most Arduino boards. +// give it a name: +int led = 13; + + +// 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() { + lunga() ; + lunga() ; + breve(); + breve(); + varia(3000); +} + +// Funzioni personalizzate: nella scheda funzioni. diff --git a/programming/funzioni/blink_with_functions/funzioni.ino b/programming/funzioni/blink_with_functions/funzioni.ino new file mode 100644 index 0000000..25568f1 --- /dev/null +++ b/programming/funzioni/blink_with_functions/funzioni.ino @@ -0,0 +1,51 @@ +// Funzioni personalizzate +// Un scheda e' un documento che viene concatenato allo sketch originale + +void lunga() { + // Blink con pausa lunga + + digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) + delay(1000); // wait for a second + digitalWrite(led, LOW); // turn the LED off by making the voltage LOW + delay(1000); // wait for a second +} + +void breve() { + // Blink con pausa breve + + digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) + delay(200); // wait for a second + digitalWrite(led, LOW); // turn the LED off by making the voltage LOW + delay(1000); // wait for a second +} + +void varia(int a = 300) { // Varia has a default value, the user can override it with an argument + // Lampeggia per un tempo impostato dall'utente, + // il default e' 300ms + + digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) + delay(a); // wait for a second + digitalWrite(led, LOW); // turn the LED off by making the voltage LOW + delay(a); // wait for a second + +} + +void lampeggia(int ripetizioni) { + // Accende un LED per un numero stabilito di volte + + // Questa funziona accetta un parametro: ripetizioni + int i = 0; + while (i < ripetizioni) { + rapido(); // accende e spegne rapidamente il LED + i = i + 1 ; // incrementa l'iteratore + // i++ ; // equivalente + } +} + +int area(int latoA, int latoB) { + // Calcola l'area di un rettangolo + // e ritorna il valore calcolato: questa funzione ha un valore di ritorno + // dichiarato come int + + return(latoA * latoB); +} diff --git a/programming/funzioni/scope_1/scope_1.ino b/programming/funzioni/scope_1/scope_1.ino new file mode 100644 index 0000000..8e52430 --- /dev/null +++ b/programming/funzioni/scope_1/scope_1.ino @@ -0,0 +1,49 @@ +/* + Scope + + Variabili globali e locali rispetto a una funzione + Le variabili dichiarate al di fuori di funzioni + sono globali e accessibili a tutti, + + Le variabili dichiarate all'interno di una funzione + sono locali e accessibili solo a questa, + */ + + +boolean sposato = 1 ; // Variabile globale +void setup(){ + Serial.begin(9600); +} + +void loop() { +Serial.print("In standard mode sposato = "); +Serial.println(sposato); + +Serial.print("In vacanza mode sposato = "); +Serial.println(inVacanza(sposato)); + +Serial.print("Tornato a casa sposato = "); +Serial.println(sposato); + +// Global +Serial.print("In vacanza global mode sposato = "); +Serial.println(inVacanzaG()); + +Serial.print("Stato di sposato = "); +Serial.println(sposato); + +// Termine programma +Serial.flush(); +exit(0); +} + +// Funzioni + +boolean inVacanza(boolean sposato){ // variabile locale + sposato = 0 ; + return sposato; +} +boolean inVacanzaG(){ + sposato = 0 ; // Variabile globale + return sposato; +} diff --git a/programming/head_tails_ino/head_tails_ino.ino b/programming/head_tails_ino/head_tails_ino.ino new file mode 100644 index 0000000..7102f13 --- /dev/null +++ b/programming/head_tails_ino/head_tails_ino.ino @@ -0,0 +1,63 @@ +/* + Head tails + Generates a random number in order to simulate a coin toss. + + + Phisical LEDS and serial debug. + + This example code is in the public domain. + */ + +// 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 ; // 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. +int hCount = 0; +int tCount = 0; +int runs = 0 ; + +// the setup routine runs once when you press reset: +void setup() { + // initialize the digital pin as an output. + pinMode(head, OUTPUT); + pinMode(tail, OUTPUT); + randomSeed(analogRead(0)); // Random initializer + Serial.begin(9600); + Serial.println("Initializing random sequence, please wait for results."); +} + +// the loop routine runs over and over again forever: +void loop() { + randomNumber = random(); + digitalWrite(head, LOW); + digitalWrite(tail, LOW); + delay(REST); // wait a bit + if (randomNumber % 2 == 1) { + digitalWrite(head, HIGH);// turn the LED on ON + hCount++ ; + } + else { + digitalWrite(tail, HIGH);// turn the LED ON + tCount++ ; + } + + // 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); + Serial.print("Tails: \t") ; + Serial.println(tCount); + 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 diff --git a/shift_register/shiftOut_binary_count/shiftOut_binary_count.ino b/shift_register/shiftOut_binary_count/shiftOut_binary_count.ino deleted file mode 100644 index 5ac868c..0000000 --- a/shift_register/shiftOut_binary_count/shiftOut_binary_count.ino +++ /dev/null @@ -1,57 +0,0 @@ - -//**************************************************************// -// Name : shiftOutCode, Hello World -// Author : Carlyn Maw,Tom Igoe, David A. Mellis -// Date : 25 Oct, 2006 -// Modified: 23 Mar 2010 -// Version : 2.0 -// Notes : Code for using a 74HC595 Shift Register // -// : to count from 0 to 255 -//**************************************************************** - -//Pin connected to ST_CP of 74HC595 -int latchPin = 8; -//Pin connected to SH_CP of 74HC595 -int clockPin = 12; -////Pin connected to DS of 74HC595 -int dataPin = 11; - - - -void setup() { - //set pins to output so you can control the shift register - pinMode(latchPin, OUTPUT); - pinMode(clockPin, OUTPUT); - pinMode(dataPin, OUTPUT); - // Serial Debug - Serial.begin(9600); - Serial.print("Decimal"); - Serial.print("\t"); - Serial.println("Binary"); -} - -void loop() { - // count from 0 to 255 and display the number - // on the LEDs - for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) { - // take the latchPin low so - // the LEDs don't change while you're sending in bits: - digitalWrite(latchPin, LOW); - - // shift out the bits: - shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay); - - //take the latch pin high so the LEDs will light up: - digitalWrite(latchPin, HIGH); - // Serial Debug - Serial.print(numberToDisplay); - Serial.print("\t"); - Serial.println(numberToDisplay, BIN); - // pause before next value: - delay(200); - } -} - - - - diff --git a/shift_register/shift_register_8bit/shift_register_8bit.ino b/shift_register/shift_register_8bit/shift_register_8bit.ino deleted file mode 100644 index 7ce253e..0000000 --- a/shift_register/shift_register_8bit/shift_register_8bit.ino +++ /dev/null @@ -1,43 +0,0 @@ -//**************************************************************// -// Name : shiftOutCode, Hello World -// Author : Carlyn Maw,Tom Igoe, David A. Mellis -// Date : 25 Oct, 2006 -// Modified: 23 Mar 2010 -// Version : 2.0 -// Notes : Code for using a 74HC595 Shift Register -// -// : to count from 0 to 255 -//**************************************************************** - - -//Pin connected to ST_CP of 74HC595 -int latchPin = 8; -//Pin connected to SH_CP of 74HC595 -int clockPin = 12; -////Pin connected to DS of 74HC595 -int dataPin = 11; -void setup() { - //set pins to output so you can control the shift register - pinMode(latchPin, OUTPUT); - -pinMode(clockPin, OUTPUT); -pinMode(dataPin, OUTPUT); -} -void loop() { - // count from 0 to 255 and display the number - // on the LEDs - for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) { - // take the latchPin low so - // the LEDs don’t change while you’re sending in bits: - digitalWrite(latchPin, LOW); - // shift out the bits: - shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay); - //take the latch pin high so the LEDs will light up: - digitalWrite(latchPin, HIGH); - // pause before next value: - delay(500); - } -} - - - diff --git a/shift_register/shift_register_custom_pattern_4/shift_register_custom_pattern_4.ino b/shift_register/shift_register_custom_pattern_4/shift_register_custom_pattern_4.ino deleted file mode 100644 index c5e1da7..0000000 --- a/shift_register/shift_register_custom_pattern_4/shift_register_custom_pattern_4.ino +++ /dev/null @@ -1,136 +0,0 @@ - -/* - Shift Register Example - Turning on the outputs of a 74HC595 using an array - - Hardware: - * 74HC595 shift register - * LEDs attached to each of the outputs of the shift register - - */ -//Pin connected to ST_CP of 74HC595 -int latchPin = 8; -//Pin connected to SH_CP of 74HC595 -int clockPin = 12; -////Pin connected to DS of 74HC595 -int dataPin = 11; - -//holders for infromation you're going to pass to shifting function -byte data; -byte dataArray[10]; - -void setup() { - //set pins to output because they are addressed in the main loop - pinMode(latchPin, OUTPUT); - Serial.begin(9600); - - //Arduino doesn't seem to have a way to write binary straight into the code - //so these values are in HEX. Decimal would have been fine, too. - dataArray[0] = 0xFF; //11111111 - dataArray[1] = 0xFE; //11111110 - dataArray[2] = 0xFC; //11111100 - dataArray[3] = 0xF8; //11111000 - dataArray[4] = 0xF0; //11110000 - dataArray[5] = 0xE0; //11100000 - dataArray[6] = 0xC0; //11000000 - dataArray[7] = 0x80; //10000000 - dataArray[8] = 0x00; //00000000 - dataArray[9] = 0x38; //11100000 - - //function that blinks all the LEDs - //gets passed the number of blinks and the pause time - blinkAll_2Bytes(2,500); -} - -void loop() { - - for (int j = 0; j < 10; j++) { - //load the light sequence you want from array - data = dataArray[j]; - //ground latchPin and hold low for as long as you are transmitting - digitalWrite(latchPin, 0); - //move 'em out - shiftOut(dataPin, clockPin, data); - //return the latch pin high to signal chip that it - //no longer needs to listen for information - digitalWrite(latchPin, 1); - delay(300); - } -} - - - -// the heart of the program -void shiftOut(int myDataPin, int myClockPin, byte myDataOut) { - // This shifts 8 bits out MSB first, - //on the rising edge of the clock, - //clock idles low - - //internal function setup - int i=0; - int pinState; - pinMode(myClockPin, OUTPUT); - pinMode(myDataPin, OUTPUT); - - //clear everything out just in case to - //prepare shift register for bit shifting - digitalWrite(myDataPin, 0); - digitalWrite(myClockPin, 0); - - //for each bit in the byte myDataOut� - //NOTICE THAT WE ARE COUNTING DOWN in our for loop - //This means that %00000001 or "1" will go through such - //that it will be pin Q0 that lights. - for (i=7; i>=0; i--) { - digitalWrite(myClockPin, 0); - - //if the value passed to myDataOut and a bitmask result - // true then... so if we are at i=6 and our value is - // %11010100 it would the code compares it to %01000000 - // and proceeds to set pinState to 1. - if ( myDataOut & (1<= count){ - index = 0; - } -} - diff --git a/shift_register/shift_register_pattern/sketch_jan27c/sketch_jan27c.ino b/shift_register/shift_register_pattern/sketch_jan27c/sketch_jan27c.ino deleted file mode 100644 index c5e1da7..0000000 --- a/shift_register/shift_register_pattern/sketch_jan27c/sketch_jan27c.ino +++ /dev/null @@ -1,136 +0,0 @@ - -/* - Shift Register Example - Turning on the outputs of a 74HC595 using an array - - Hardware: - * 74HC595 shift register - * LEDs attached to each of the outputs of the shift register - - */ -//Pin connected to ST_CP of 74HC595 -int latchPin = 8; -//Pin connected to SH_CP of 74HC595 -int clockPin = 12; -////Pin connected to DS of 74HC595 -int dataPin = 11; - -//holders for infromation you're going to pass to shifting function -byte data; -byte dataArray[10]; - -void setup() { - //set pins to output because they are addressed in the main loop - pinMode(latchPin, OUTPUT); - Serial.begin(9600); - - //Arduino doesn't seem to have a way to write binary straight into the code - //so these values are in HEX. Decimal would have been fine, too. - dataArray[0] = 0xFF; //11111111 - dataArray[1] = 0xFE; //11111110 - dataArray[2] = 0xFC; //11111100 - dataArray[3] = 0xF8; //11111000 - dataArray[4] = 0xF0; //11110000 - dataArray[5] = 0xE0; //11100000 - dataArray[6] = 0xC0; //11000000 - dataArray[7] = 0x80; //10000000 - dataArray[8] = 0x00; //00000000 - dataArray[9] = 0x38; //11100000 - - //function that blinks all the LEDs - //gets passed the number of blinks and the pause time - blinkAll_2Bytes(2,500); -} - -void loop() { - - for (int j = 0; j < 10; j++) { - //load the light sequence you want from array - data = dataArray[j]; - //ground latchPin and hold low for as long as you are transmitting - digitalWrite(latchPin, 0); - //move 'em out - shiftOut(dataPin, clockPin, data); - //return the latch pin high to signal chip that it - //no longer needs to listen for information - digitalWrite(latchPin, 1); - delay(300); - } -} - - - -// the heart of the program -void shiftOut(int myDataPin, int myClockPin, byte myDataOut) { - // This shifts 8 bits out MSB first, - //on the rising edge of the clock, - //clock idles low - - //internal function setup - int i=0; - int pinState; - pinMode(myClockPin, OUTPUT); - pinMode(myDataPin, OUTPUT); - - //clear everything out just in case to - //prepare shift register for bit shifting - digitalWrite(myDataPin, 0); - digitalWrite(myClockPin, 0); - - //for each bit in the byte myDataOut� - //NOTICE THAT WE ARE COUNTING DOWN in our for loop - //This means that %00000001 or "1" will go through such - //that it will be pin Q0 that lights. - for (i=7; i>=0; i--) { - digitalWrite(myClockPin, 0); - - //if the value passed to myDataOut and a bitmask result - // true then... so if we are at i=6 and our value is - // %11010100 it would the code compares it to %01000000 - // and proceeds to set pinState to 1. - if ( myDataOut & (1< 0) { - // ASCII '0' through '9' characters are - // represented by the values 48 through 57. - // so if the user types a number from 0 through 9 in ASCII, - // you can subtract 48 to get the actual value: - int bitToSet = Serial.read() - 48; - - // write to the shift register with the correct bit set high: - registerWrite(bitToSet, HIGH); - } -} - -// This method sends bits to the shift register: - -void registerWrite(int whichPin, int whichState) { -// the bits you want to send - byte bitsToSend = 0; - - // turn off the output so the pins don't light up - // while you're shifting bits: - digitalWrite(latchPin, LOW); - - // turn on the next highest bit in bitsToSend: - bitWrite(bitsToSend, whichPin, whichState); - - // shift the bits out: - shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend); - - // turn on the output so the LEDs can light up: - digitalWrite(latchPin, HIGH); - delay(300); - -} -