├── mando-distancia ├── MandoDistancia.fzz ├── MandoDistanciaCompacto.fzz └── MandoDistancia │ └── MandoDistancia.ino ├── README.md ├── led ├── README.md ├── build.sh └── led.cpp ├── juego-numerico ├── README.md └── juego-numerico.ino ├── led-serial ├── README.md ├── serial_ino │ └── serial_ino.ino ├── serial.cpp └── serial2.cpp ├── termostato └── termostato.ino └── juego-numerico-sonido └── juego-numerico-sonido.ino /mando-distancia/MandoDistancia.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aarroyoc/arduino/master/mando-distancia/MandoDistancia.fzz -------------------------------------------------------------------------------- /mando-distancia/MandoDistanciaCompacto.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aarroyoc/arduino/master/mando-distancia/MandoDistanciaCompacto.fzz -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Arduino 2 | ======= 3 | These are our Arduino samples. It works on Arduino UNO R3 and it's licensed under the Public Domain license if no explicit license is named. 4 | -------------------------------------------------------------------------------- /led/README.md: -------------------------------------------------------------------------------- 1 | LED sample implemented on RAW AVR LIBC 2 | ====================================== 3 | 4 | This easy LED program uses the raw AVR LIBC and it contains the build instructions for Arduino UNO R3. 5 | 6 | To run it: 7 | ``` 8 | ./build.sh 9 | ``` 10 | 11 | But remember to change the Arduino path if it isn't under /dev/ttyACM0 12 | -------------------------------------------------------------------------------- /led/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ##Specific script for Arduino UNO R3 with ATmega328p 3 | avr-g++ -DF_CPU=16000000UL -mmcu=atmega328p -Os -c -o led.o led.cpp 4 | avr-g++ -DF_CPU=16000000UL -mmcu=atmega328p -Os -o led.elf led.o 5 | avr-objcopy -O ihex led.elf led.hex 6 | ##RUN IT LATER, WHEN YOU REBOOT 7 | avrdude -F -V -c arduino -p ATMEGA328P -P /dev/ttyACM0 -b 115200 -U flash:w:led.hex 8 | -------------------------------------------------------------------------------- /juego-numerico/README.md: -------------------------------------------------------------------------------- 1 | Juego Numérico en Arduino 2 | ========================= 3 | 4 | En este pequeño pero entretenido juego deberemos dar al botón justo en el momento en que el número pedido aparece en la pantalla. Se adjunta el código en Processing y su diseño en Protoboard es similar a este: 5 | 6 | ![Diseño de prototipo](https://raw.githubusercontent.com/AdrianArroyoCalle/arduino/master/juego-numerico/protoboard.svg) 7 | -------------------------------------------------------------------------------- /led-serial/README.md: -------------------------------------------------------------------------------- 1 | LED Serial Communication 2 | ======================== 3 | 4 | This example shows how to communicate between Arduino and a PC. You should compile via Arduino IDE the simple_ino sketch and the simple2.cpp on your PC. make sure to have installed libSerial 5 | Then, start the Arduino and on your command line put: 6 | ``` 7 | ./simple2 -d/dev/ttyXXX 8 | ``` 9 | Where /dev/ttyXXX is the place of your Arduino 10 | 11 | ###Compilation 12 | ``` 13 | g++ -o simple2 simple2.cpp -lserial 14 | ``` 15 | -------------------------------------------------------------------------------- /led/led.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | enum { 5 | BLINK_DELAY_MS = 500, 6 | }; 7 | 8 | int main (void) 9 | { 10 | /* set pin 5 of PORTB for output*/ 11 | DDRB |= _BV(DDB5); 12 | DDRB |= _BV(DDB0); 13 | DDRD |= _BV(DDD7); 14 | 15 | while(1) { 16 | /* set pin 5 high to turn led on */ 17 | PORTB |= _BV(PORTB5); 18 | PORTB |= _BV(PORTB0); 19 | PORTD |= _BV(PORTD7); 20 | _delay_ms(BLINK_DELAY_MS); 21 | 22 | /* set pin 5 low to turn led off */ 23 | PORTB &= ~_BV(PORTB5); 24 | PORTB &= ~_BV(PORTB0); 25 | _delay_ms(BLINK_DELAY_MS); 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /led-serial/serial_ino/serial_ino.ino: -------------------------------------------------------------------------------- 1 | int ledPin = 13; // select the pin for the LED 2 | int val = 0; // variable to store the data from the serial port 3 | 4 | void setup() { 5 | pinMode(ledPin,OUTPUT); // declare the LED's pin as output 6 | Serial.begin(57600); // connect to the serial port 7 | } 8 | 9 | void loop () { 10 | val = Serial.read(); // read the serial port 11 | // if the stored value is a single-digit number, blink the LED that number 12 | if (val > '0' && val <= '9' ) { 13 | val = val - '0'; // convert from character to number 14 | for (int i=0; i 2 | #include 3 | 4 | using namespace LibSerial; 5 | 6 | int main(int argc, char** argv) 7 | { 8 | char parpadeos[256]; 9 | SerialStream arduino("/dev/ttyACM0", std::ios_base::out); 10 | arduino.SetBaudRate(SerialStreamBuf::BAUD_57600); 11 | arduino.SetCharSize(SerialStreamBuf::CHAR_SIZE_8); 12 | arduino.SetFlowControl(SerialStreamBuf::FLOW_CONTROL_NONE); 13 | arduino.SetParity(SerialStreamBuf::PARITY_NONE); 14 | arduino.SetNumOfStopBits(1); 15 | while(1){ 16 | std::cout << "Parpadeos?" << std::endl; 17 | std::cin >> parpadeos; 18 | arduino << parpadeos; 19 | } 20 | /*const int Dsize = 2; 21 | char buffer[1]; 22 | buffer[0] = 125; //0b00000001; 23 | buffer[1] = '\0'; 24 | bitset(buffer[0]); 25 | //myss << buffer; 26 | myss.write(buffer,1);*/ 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /termostato/termostato.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | float tempC; 4 | int tempPin = A5; // Definimos la entrada en pin A0 5 | 6 | LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 7 | 8 | byte celsius[8] = { B11000, B11000, B00111, B01000, B01000, B01000, B01000, B00111 }; 9 | 10 | void setup() 11 | { 12 | // Abre puerto serial y lo configura a 9600 bps 13 | Serial.begin(9600); 14 | lcd.createChar(0,celsius); 15 | lcd.begin(16,2); 16 | lcd.print("Termostato LM35"); 17 | } 18 | void loop() 19 | { 20 | // Lee el valor desde el sensor 21 | tempC = analogRead(tempPin); 22 | 23 | // Convierte el valor a temperatura 24 | tempC = (5.0 * tempC * 100.0)/1024.0; 25 | 26 | // Envia el dato al puerto serial 27 | Serial.print(tempC); 28 | Serial.print(" grados Celsius\n"); 29 | 30 | lcd.setCursor(0,1); 31 | lcd.print(tempC); 32 | lcd.print(" "); 33 | lcd.write(byte(0)); 34 | 35 | // Espera cinco segundo para repetir el loop 36 | delay(5000); 37 | } 38 | -------------------------------------------------------------------------------- /mando-distancia/MandoDistancia/MandoDistancia.ino: -------------------------------------------------------------------------------- 1 | unsigned int down[]={7482,8850,-4450,550,-1700,550,-550,500,-600,550,-550,600,-550,500,-600,550,-550,550,-550,500,-650,500,-1700,500,-1700,550,-1700,500,-1700,500,-1700,550,-1700,500,-1700,500,-600,550,-550,600,-550,500,-1700,550,-550,500,-650,500,-1700,500,-600,500,-1700,550,-1700,550,-1650,550,-550,550,-1700,500,-1700,500,-650,500,-1700,500}; 2 | 3 | /* LED should be on PIN 3 */ 4 | 5 | #include 6 | 7 | IRsend irsend; 8 | int SUBIR=5; 9 | int BAJAR=6; 10 | 11 | void setup(){ 12 | Serial.begin(9600); 13 | pinMode(SUBIR,INPUT); 14 | pinMode(BAJAR,INPUT); 15 | } 16 | 17 | void loop(){ 18 | int subir=digitalRead(SUBIR); 19 | int bajar=digitalRead(BAJAR); 20 | 21 | if(subir == HIGH) 22 | { 23 | irsend.sendNEC(0x807F22DD,32); 24 | Serial.println("Send NEC"); 25 | delay(100); 26 | }else if(bajar == HIGH){ 27 | //irsend.sendRaw(down,16,2); 28 | irsend.sendNEC(0x807F12ED,32); 29 | Serial.println("Send JVC"); 30 | delay(100); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /led-serial/serial2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | using namespace LibSerial; 8 | 9 | int main (int argc, char **argv) { 10 | 11 | int oc; 12 | string dev; 13 | bool dsp = false; 14 | while ((oc = getopt(argc, argv, ":d:")) != -1) { 15 | switch(oc) { 16 | case 'd': 17 | //device 18 | cout << "Dispositivo: "; 19 | dev = optarg; 20 | cout << " :: " << dev << endl; 21 | dsp = true; 22 | break; 23 | case ':': 24 | cerr << "Missing argument " << endl; 25 | return -1; 26 | break; 27 | } 28 | } 29 | 30 | if (!dsp) { 31 | dev = "/dev/ttyACM0"; 32 | } 33 | SerialStream serial_port(dev,std::ios_base::out); 34 | serial_port.SetBaudRate(SerialStreamBuf::BAUD_57600); 35 | serial_port.SetCharSize( SerialStreamBuf::CHAR_SIZE_8); 36 | 37 | char num; 38 | while (1) { 39 | cout << "Number of blinks? : "; 40 | cin >> num; 41 | serial_port << num; 42 | } 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /juego-numerico/juego-numerico.ino: -------------------------------------------------------------------------------- 1 | /* Tragaperras */ 2 | 3 | int salidas[]={12, 11, 10, 9, 8, 7, 6}; 4 | int correcto=4; 5 | int fallo=5; 6 | int boton=3; 7 | int contador=0; 8 | 9 | int pedido=5; 10 | int stopDisplay=0; 11 | 12 | void displayNumber(int number) 13 | { 14 | for(int i=0;i<7;i++) 15 | digitalWrite(salidas[i],LOW); 16 | if(number==2 || number==3 || number==4 || number==5 || number==6 || number==8 || number==9) 17 | digitalWrite(salidas[0],HIGH); 18 | if(number==0 || number==4 || number==5 || number==6 || number==8 || number==9) 19 | digitalWrite(salidas[1],HIGH); 20 | if(number==0 || number==2 || number==3 || number==5 || number==6 || number==7 || number==8 || number==9) 21 | digitalWrite(salidas[2],HIGH); 22 | if(number==0 || number==1 || number==2 || number==3 || number==4 || number==7 || number==8 || number==9) 23 | digitalWrite(salidas[3],HIGH); 24 | if(number==0 || number==2 || number==6 || number==8) 25 | digitalWrite(salidas[4],HIGH); 26 | if(number==0 || number==2 || number==3 || number==5 || number==6 || number==8) 27 | digitalWrite(salidas[5],HIGH); 28 | if(number!=2) 29 | digitalWrite(salidas[6],HIGH); 30 | } 31 | 32 | void setup() 33 | { 34 | for(int i=0;i<7;i++) 35 | pinMode(salidas[i],OUTPUT); 36 | pinMode(correcto,OUTPUT); 37 | pinMode(fallo,OUTPUT); 38 | pinMode(boton,INPUT); 39 | randomSeed(analogRead(0)); 40 | pedido=random(0,10); 41 | displayNumber(pedido); 42 | delay(1000); 43 | } 44 | void loop() 45 | { 46 | if(stopDisplay==0) 47 | { 48 | displayNumber(contador); 49 | int currentTime=millis(); 50 | int nowTime=millis(); 51 | do{ 52 | int input=digitalRead(boton); 53 | if(input>0) 54 | { 55 | if(pedido==contador) 56 | digitalWrite(correcto,HIGH); 57 | else 58 | digitalWrite(fallo, HIGH); 59 | 60 | stopDisplay=1; 61 | } 62 | nowTime=millis(); 63 | }while((nowTime-currentTime)<250); 64 | contador++; 65 | if(contador==10) 66 | contador=0; 67 | 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /juego-numerico-sonido/juego-numerico-sonido.ino: -------------------------------------------------------------------------------- 1 | /* Tragaperras */ 2 | /************************************************* 3 | * Public Constants 4 | *************************************************/ 5 | 6 | #define NOTE_B0 31 7 | #define NOTE_C1 33 8 | #define NOTE_CS1 35 9 | #define NOTE_D1 37 10 | #define NOTE_DS1 39 11 | #define NOTE_E1 41 12 | #define NOTE_F1 44 13 | #define NOTE_FS1 46 14 | #define NOTE_G1 49 15 | #define NOTE_GS1 52 16 | #define NOTE_A1 55 17 | #define NOTE_AS1 58 18 | #define NOTE_B1 62 19 | #define NOTE_C2 65 20 | #define NOTE_CS2 69 21 | #define NOTE_D2 73 22 | #define NOTE_DS2 78 23 | #define NOTE_E2 82 24 | #define NOTE_F2 87 25 | #define NOTE_FS2 93 26 | #define NOTE_G2 98 27 | #define NOTE_GS2 104 28 | #define NOTE_A2 110 29 | #define NOTE_AS2 117 30 | #define NOTE_B2 123 31 | #define NOTE_C3 131 32 | #define NOTE_CS3 139 33 | #define NOTE_D3 147 34 | #define NOTE_DS3 156 35 | #define NOTE_E3 165 36 | #define NOTE_F3 175 37 | #define NOTE_FS3 185 38 | #define NOTE_G3 196 39 | #define NOTE_GS3 208 40 | #define NOTE_A3 220 41 | #define NOTE_AS3 233 42 | #define NOTE_B3 247 43 | #define NOTE_C4 262 44 | #define NOTE_CS4 277 45 | #define NOTE_D4 294 46 | #define NOTE_DS4 311 47 | #define NOTE_E4 330 48 | #define NOTE_F4 349 49 | #define NOTE_FS4 370 50 | #define NOTE_G4 392 51 | #define NOTE_GS4 415 52 | #define NOTE_A4 440 53 | #define NOTE_AS4 466 54 | #define NOTE_B4 494 55 | #define NOTE_C5 523 56 | #define NOTE_CS5 554 57 | #define NOTE_D5 587 58 | #define NOTE_DS5 622 59 | #define NOTE_E5 659 60 | #define NOTE_F5 698 61 | #define NOTE_FS5 740 62 | #define NOTE_G5 784 63 | #define NOTE_GS5 831 64 | #define NOTE_A5 880 65 | #define NOTE_AS5 932 66 | #define NOTE_B5 988 67 | #define NOTE_C6 1047 68 | #define NOTE_CS6 1109 69 | #define NOTE_D6 1175 70 | #define NOTE_DS6 1245 71 | #define NOTE_E6 1319 72 | #define NOTE_F6 1397 73 | #define NOTE_FS6 1480 74 | #define NOTE_G6 1568 75 | #define NOTE_GS6 1661 76 | #define NOTE_A6 1760 77 | #define NOTE_AS6 1865 78 | #define NOTE_B6 1976 79 | #define NOTE_C7 2093 80 | #define NOTE_CS7 2217 81 | #define NOTE_D7 2349 82 | #define NOTE_DS7 2489 83 | #define NOTE_E7 2637 84 | #define NOTE_F7 2794 85 | #define NOTE_FS7 2960 86 | #define NOTE_G7 3136 87 | #define NOTE_GS7 3322 88 | #define NOTE_A7 3520 89 | #define NOTE_AS7 3729 90 | #define NOTE_B7 3951 91 | #define NOTE_C8 4186 92 | #define NOTE_CS8 4435 93 | #define NOTE_D8 4699 94 | #define NOTE_DS8 4978 95 | 96 | int salidas[]={12, 11, 10, 9, 8, 7, 6}; 97 | int correcto=4; 98 | int fallo=5; 99 | int boton=2; 100 | int contador=0; 101 | 102 | int pedido=5; 103 | int stopDisplay=0; 104 | 105 | void displayNumber(int number) 106 | { 107 | for(int i=0;i<7;i++) 108 | digitalWrite(salidas[i],LOW); 109 | if(number==2 || number==3 || number==4 || number==5 || number==6 || number==8 || number==9) 110 | digitalWrite(salidas[0],HIGH); 111 | if(number==0 || number==4 || number==5 || number==6 || number==8 || number==9) 112 | digitalWrite(salidas[1],HIGH); 113 | if(number==0 || number==2 || number==3 || number==5 || number==6 || number==7 || number==8 || number==9) 114 | digitalWrite(salidas[2],HIGH); 115 | if(number==0 || number==1 || number==2 || number==3 || number==4 || number==7 || number==8 || number==9) 116 | digitalWrite(salidas[3],HIGH); 117 | if(number==0 || number==2 || number==6 || number==8) 118 | digitalWrite(salidas[4],HIGH); 119 | if(number==0 || number==2 || number==3 || number==5 || number==6 || number==8) 120 | digitalWrite(salidas[5],HIGH); 121 | if(number!=2) 122 | digitalWrite(salidas[6],HIGH); 123 | } 124 | 125 | void playWinSong(){ 126 | int melody[] = { 127 | NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4}; 128 | 129 | // note durations: 4 = quarter note, 8 = eighth note, etc.: 130 | int noteDurations[] = {4, 8, 8, 4,4,4,4,4 }; 131 | 132 | for (int thisNote = 0; thisNote < 8; thisNote++) { 133 | 134 | // to calculate the note duration, take one second 135 | // divided by the note type. 136 | //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. 137 | int noteDuration = 1000/noteDurations[thisNote]; 138 | tone(3, melody[thisNote],noteDuration); 139 | 140 | // to distinguish the notes, set a minimum time between them. 141 | // the note's duration + 30% seems to work well: 142 | int pauseBetweenNotes = noteDuration * 1.30; 143 | delay(pauseBetweenNotes); 144 | // stop the tone playing: 145 | noTone(3); 146 | } 147 | 148 | } 149 | void setup() 150 | { 151 | for(int i=0;i<7;i++) 152 | pinMode(salidas[i],OUTPUT); 153 | pinMode(correcto,OUTPUT); 154 | pinMode(fallo,OUTPUT); 155 | pinMode(boton,INPUT); 156 | randomSeed(analogRead(0)); 157 | pedido=random(0,10); 158 | displayNumber(pedido); 159 | delay(1000); 160 | } 161 | void loop() 162 | { 163 | if(stopDisplay==0) 164 | { 165 | displayNumber(contador); 166 | int currentTime=millis(); 167 | int nowTime=millis(); 168 | do{ 169 | int input=digitalRead(boton); 170 | if(input>0) 171 | { 172 | if(pedido==contador) 173 | digitalWrite(correcto,HIGH); 174 | else 175 | digitalWrite(fallo, HIGH); 176 | stopDisplay=1; 177 | playWinSong(); 178 | } 179 | nowTime=millis(); 180 | }while((nowTime-currentTime)<100); 181 | contador++; 182 | if(contador==10) 183 | contador=0; 184 | } 185 | } 186 | --------------------------------------------------------------------------------