From f1049e58baf973e21c716ef697458b1384f02b78 Mon Sep 17 00:00:00 2001 From: Andrea Manni Date: Thu, 26 Mar 2015 17:04:59 +0100 Subject: [PATCH] RF e keypad --- README | 125 ++++++++++++++++++ basic/buttons/button_1/button_1.ino | 4 +- .../button_2_serial_debug.ino | 4 +- .../pwm_1_soluzione_doppio_while_byte.ino | 37 ++++++ .../pwm/pwm_1_while_byte/pwm_1_while_byte.ino | 3 +- hardware/keypad/keypad.ino | 67 ++++++++++ hardware/keypad/keypad_ino/keypad_ino.ino | 44 ++++++ hardware/rf315_433/reciver/reciver.ino | 36 +++++ hardware/rf315_433/trasmitter/trasmitter.ino | 35 +++++ 9 files changed, 350 insertions(+), 5 deletions(-) create mode 100644 basic/pwm/pwm_1_soluzione_doppio_while_byte/pwm_1_soluzione_doppio_while_byte.ino create mode 100644 hardware/keypad/keypad.ino create mode 100644 hardware/keypad/keypad_ino/keypad_ino.ino create mode 100644 hardware/rf315_433/reciver/reciver.ino create mode 100644 hardware/rf315_433/trasmitter/trasmitter.ino diff --git a/README b/README index 492f5a4..e432432 100644 --- a/README +++ b/README @@ -27,3 +27,128 @@ http://git.andreamanni.com/web?p=sketchbook_andrea;a=snapshot;h=HEAD;sf=tgz :: wget http://git.andreamanni.com/web?p=sketchbook_andrea;a=snapshot;h=HEAD;sf=tgz +Ordine sketches +================ +Ordine da seguire per gli esercizi a seconda della traccia decisa per il corso. + + +Digital output +================================ + +Tutti i blinks in ordine +Dovrebbero coprire gli argomenti per +- istruzioni +- sequenze di istruzioni + +Cicli iterativi vengono visti con bottoni mentre i cicli iterativi sono +presentati con i PWM. + + +Debug Seriale +================================ + +basic/serial_debug/serial_hello_world/ + +Digital input +================================ +Cicli condizionali + +basic/buttons/button_1 +basic/buttons/button_2_serial_debug/ +(pull down e pull up) + + +Analog input +================================ + +basic/analog_input/analogInput_1/analogInput_1.ino +basic/analog_input/analogInput_2_serial/analogInput_2_serial.ino + + +Programmazione +================================ +Data types: http://www.ladyada.net/learn/arduino/lesson4.html +fare byte - int - long +Magari uno script con serial print, eventualmente anche esadecimale + + +Analog Output +================================ +Cicli iterativi while + +basic/pwm/pwm_0_manuale/pwm_0_manuale.ino Dimostrativo +basic/pwm/pwm_1_while_byte/pwm_1_while_byte.ino +basic/pwm/pwm_1_soluzione_doppio_while_byte/pwm_1_soluzione_doppio_while_byte.ino + + +Programmazione: operatori binari +================================ + +programming/operators/operator_1_basic/operator_1_basic.ino +programming/operators/operator_2_comparison/operator_2_comparison.ino + + +Analog Output +================================ +Cicli iterativi For, operatore ternario + +basic/pwm/pwm_2_for_loop/pwm_2_for_loop.ino + + +Programmazione: operatori logici +================================ + +programming/operators/operator_3_logic/operator_3_logic.ino + + +Analog Output +================================ + +basic/pwm/pwm_3_fade_reverser/pwm_3_fade_reverser.ino +basic/pwm/pwm_4_analog_input/pwm_4_analog_input.ino + + +Status +========== + +Completata la parte di: + +- fondamenti di programmazione +- input / output digitali e analogici + + +State machine +================= +Gestione stato di un bottone +Simple multitasking con millis() e due blink contemporanei (questo si potrebbe + fare anche dopo). + + +Sensori e attuatori +======================= +Fare un input e un output a rotazione + +- piezo, suoni e knocking +- sensore luminosita' +- LED RGB (array) +- sensore temperatura +- pulsante capacitivo +- motori DC con transistor e diodo +- motori step + + +Devices +============= + +Utilizzare specifici devices: + +- sensore a ultrasuoni +- PIR +- infrarossi / telecomando IR +- display LCD a due righe +- shift register +- POV persistence of vision +- display a matrice e a "8" +- connessione seriale via radio +- programmare un Attiny85 con Arduino +- ethernet e WIFI diff --git a/basic/buttons/button_1/button_1.ino b/basic/buttons/button_1/button_1.ino index 15e9abe..27987bc 100644 --- a/basic/buttons/button_1/button_1.ino +++ b/basic/buttons/button_1/button_1.ino @@ -20,10 +20,10 @@ void setup() { // the loop routine runs over and over again forever: void loop() { - if (digitalRead(input) == HIGH) { // Verifica se il PIN input e' +5v + if (digitalRead(input) == HIGH) { // Verifica se il PIN input e' +5V digitalWrite(led, HIGH); } - else { // Alterativa: se non e' +5v + if (digitalRead(input) == LOW) { // Verifica se il PIN input e' 0V digitalWrite(led, LOW); } } diff --git a/basic/buttons/button_2_serial_debug/button_2_serial_debug.ino b/basic/buttons/button_2_serial_debug/button_2_serial_debug.ino index e4866bf..443b3c1 100644 --- a/basic/buttons/button_2_serial_debug/button_2_serial_debug.ino +++ b/basic/buttons/button_2_serial_debug/button_2_serial_debug.ino @@ -1,10 +1,10 @@ /* - Input serial + Input serial debug Accensione e spegnimanto di un LED utilizzando un pin come input. - Schemi del circuito: + Schemi del circuito per bottone in pull down: - http://lab.piffa.net/schemi/button_1_bb.png - http://lab.piffa.net/schemi/button_1_schem.png */ diff --git a/basic/pwm/pwm_1_soluzione_doppio_while_byte/pwm_1_soluzione_doppio_while_byte.ino b/basic/pwm/pwm_1_soluzione_doppio_while_byte/pwm_1_soluzione_doppio_while_byte.ino new file mode 100644 index 0000000..062f1ac --- /dev/null +++ b/basic/pwm/pwm_1_soluzione_doppio_while_byte/pwm_1_soluzione_doppio_while_byte.ino @@ -0,0 +1,37 @@ +/* + Fade sali e scendi + + PWM per un LED: aumentare progressivamente la luminosita'. + Aumenta e diminuisce la luminostia' usando un ciclo while + */ + +byte led = 9 ; // Il pin ~9 e' abilitato al PWM +byte brightness = 0; // Valore iniziale per il PWM del LED + +// the setup routine runs once when you press reset: +void setup() { + pinMode(led, OUTPUT); // Il PIN nove va dichiarato come un OUTPUT +} + +void loop() { + while (brigtness < 255) { + analogWrite(led, brightness); // La funziona analogWrite utilizza il PWM + // a 8 bit integrato nel MCU: simula un serie di valori intermedi + // nell'intervallo discreto con minimo 0 (spento) e massimo 255 (acceso). + delay(10); + brightness = brightness + 1; // Incrementiamo la luminosita' + } + + while (brigtness > 0) { + analogWrite(led, brightness); // La funziona analogWrite utilizza il PWM + delay(10); + brightness = brightness - 1; // Decrementiamo la luminosita' + } + + +} +/* +- basic/pwm/pwm_3_fade_reverser/pwm_3_fade_reverser.ino +E molto piu' snello utilizzando il solo ciclo loop come iteratore +e una condizione per cambiare l'incremento +*/ diff --git a/basic/pwm/pwm_1_while_byte/pwm_1_while_byte.ino b/basic/pwm/pwm_1_while_byte/pwm_1_while_byte.ino index cf5451a..3f6de46 100644 --- a/basic/pwm/pwm_1_while_byte/pwm_1_while_byte.ino +++ b/basic/pwm/pwm_1_while_byte/pwm_1_while_byte.ino @@ -13,10 +13,11 @@ void setup() { } void loop() { - analogWrite(led, brightness++); // La funziona analogWrite utilizza il PWM + analogWrite(led, brightness); // La funziona analogWrite utilizza il PWM // a 8 bit integrato nel MCU: simula un serie di valori intermedi // nell'intervallo discreto con minimo 0 (spento) e massimo 255 (acceso). delay(10); + brightness = brightness + 1; // Incrementiamo la luminosita' } /* Domande: diff --git a/hardware/keypad/keypad.ino b/hardware/keypad/keypad.ino new file mode 100644 index 0000000..96796d8 --- /dev/null +++ b/hardware/keypad/keypad.ino @@ -0,0 +1,67 @@ +/* Keypadtest.pde + * + * Demonstrate the simplest use of the keypad library. + * + * The first step is to connect your keypad to the + * Arduino using the pin numbers listed below in + * rowPins[] and colPins[]. If you want to use different + * pins then you can change the numbers below to + * match your setup. + * + */ +#include + +const byte ROWS = 4; // Four rows +const byte COLS = 3; // Three columns +// Define the Keymap +char keys[ROWS][COLS] = { + { + '1','2','3' } + , + { + '4','5','6' } + , + { + '7','8','9' } + , + { + '#','0','*' } +}; +// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins. +byte rowPins[ROWS] = { + 9, 8, 7, 6 }; +// Connect keypad COL0, COL1 and COL2 to these Arduino pins. +byte colPins[COLS] = { + 12, 11, 10 }; + +// Create the Keypad +Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); + +#define ledpin 13 + +void setup() +{ + pinMode(ledpin,OUTPUT); + digitalWrite(ledpin, HIGH); + Serial.begin(9600); +} + +void loop() +{ + char key = kpd.getKey(); + if(key) // Check for a valid key. + { + switch (key) + { + case '*': + digitalWrite(ledpin, LOW); + break; + case '#': + digitalWrite(ledpin, HIGH); + break; + default: + Serial.println(key); + } + } +} + diff --git a/hardware/keypad/keypad_ino/keypad_ino.ino b/hardware/keypad/keypad_ino/keypad_ino.ino new file mode 100644 index 0000000..9914b05 --- /dev/null +++ b/hardware/keypad/keypad_ino/keypad_ino.ino @@ -0,0 +1,44 @@ +/* @file HelloKeypad.pde +|| @version 1.0 +|| @author Alexander Brevig +|| @contact alexanderbrevig@gmail.com +|| +|| @description +|| | Demonstrates the simplest use of the matrix Keypad library. +|| # + + Pins are 8 -> 2 +Links: +- http://www.addicore.com/v/vspfiles/downloadables/Product%20Downloadables/Project_Interface_Kit/Addicore_12-Key_Keypad_Tutorial.pdf +- https://learn.adafruit.com/biometric-security-box +*/ +#include + +const byte ROWS = 4; //four rows +const byte COLS = 3; //three columns +char keys[ROWS][COLS] = { + {'1','2','3'}, + {'4','5','6'}, + {'7','8','9'}, + {'*','0','#'} +}; +byte rowPins[ROWS] = {8,7,6,5}; //connect to the row pinouts of the keypad +byte colPins[COLS] = {4,3,2}; //connect to the column pinouts of the keypad + +// Try this if you think you have reversed the pins +//byte rowPins[ROWS] = {2, 3, 4, 5}; +//byte colPins[COLS] = {6, 7, 8}; + +Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); + +void setup(){ + Serial.begin(9600); +} + +void loop(){ + char key = keypad.getKey(); + + if (key){ + Serial.println(key); + } +} diff --git a/hardware/rf315_433/reciver/reciver.ino b/hardware/rf315_433/reciver/reciver.ino new file mode 100644 index 0000000..e4a8964 --- /dev/null +++ b/hardware/rf315_433/reciver/reciver.ino @@ -0,0 +1,36 @@ +//simple Tx on pin D12 +//Written By : Mohannad Rawashdeh +// 3:00pm , 13/6/2013 +//http://www.instructables.com/id/RF-315433-MHz-Transmitter-receiver-Module-and-Ardu/step3/Arduino-Virtual-Wire-Library/ +//.................................. +// VirtualWire.h : wiring.h -> Arduino.h +// VirtualWire.cpp : WProgram.h -> Arduino.h +#include +void setup() +{ + vw_set_ptt_inverted(true); // Required for DR3100 + vw_set_rx_pin(12); + vw_setup(4000); // Bits per sec + pinMode(13, OUTPUT); + + vw_rx_start(); // Start the receiver PLL running +} +void loop() +{ + uint8_t buf[VW_MAX_MESSAGE_LEN]; + uint8_t buflen = VW_MAX_MESSAGE_LEN; + + if (vw_get_message(buf, &buflen)) // Non-blocking + { + if(buf[0]=='1'){ + + + digitalWrite(13,1); + } + if(buf[0]=='0'){ + digitalWrite(13,0); + } + + } +} + diff --git a/hardware/rf315_433/trasmitter/trasmitter.ino b/hardware/rf315_433/trasmitter/trasmitter.ino new file mode 100644 index 0000000..3d8bf91 --- /dev/null +++ b/hardware/rf315_433/trasmitter/trasmitter.ino @@ -0,0 +1,35 @@ + + +//simple Tx on pin D12 +//Written By : Mohannad Rawashdeh +// 3:00pm , 13/6/2013 +// http://www.instructables.com/id/RF-315433-MHz-Transmitter-receiver-Module-and-Ardu/step3/Arduino-Virtual-Wire-Library/ +// VirtualWire.h : wiring.h -> Arduino.h +// VirtualWire.cpp : WProgram.h -> Arduino.h + +//.................................. +#include +char *controller; +void setup() { + pinMode(13,OUTPUT); + vw_set_ptt_inverted(true); // + vw_set_tx_pin(12); + vw_setup(4000);// speed of data transfer Kbps +} + +void loop(){ + controller="1" ; + vw_send((uint8_t *)controller, strlen(controller)); + vw_wait_tx(); // Wait until the whole message is gone + digitalWrite(13,1); + delay(2000); + controller="0" ; + vw_send((uint8_t *)controller, strlen(controller)); + vw_wait_tx(); // Wait until the whole message is gone + digitalWrite(13,0); + delay(2000); + +} + + + -- 2.39.2