-
-
Save rje1974/a196b9120285754a365d49b2988e8b09 to your computer and use it in GitHub Desktop.
Scripts De Sensores - Arduino UNO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int xpin = A0; | |
const int ypin = A1; | |
const int zpin = A2; | |
void setup() { | |
Serial.begin(9300); | |
} | |
void loop() { | |
int x = analogRead(xpin); | |
delay(1); | |
int y = analogRead(ypin); | |
delay(1); | |
int z = analogRead(zpin); | |
delay(1); | |
Serial.print("X"); | |
Serial.print(x); | |
Serial.print("\t"); | |
Serial.print("Y"); | |
Serial.print(y); | |
Serial.print("\t"); | |
Serial.print("Z"); | |
Serial.print(z); | |
Serial.print("\n"); | |
delay (500); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define met A0 | |
#define led 7 | |
int ap = 0; | |
void setup() { | |
Serial.begin(9300); | |
pinMode(met,INPUT_PULLUP); | |
pinMode(led,OUTPUT); | |
} | |
void loop() { | |
ap = analogRead(met); | |
Serial.println(ap); | |
if (ap > 520){ | |
digitalWrite(led,LOW); | |
} | |
else { | |
digitalWrite(led,HIGH); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define mpwr 8 | |
#define mdir 9 | |
void setup() { | |
Serial.begin(9300); | |
pinMode(mpwr,OUTPUT); | |
pinMode(mdir,OUTPUT); | |
} | |
void loop() { | |
analogWrite(mpwr,255); | |
digitalWrite(mdir,LOW); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <Wire.h> | |
#include <Adafruit_GFX.h> | |
#include <Adafruit_SSD1306.h> | |
#define SCREEN_WIDTH 128 // Ancho de la pantalla | |
#define SCREEN_HEIGHT 64 // Altura de la pantalla | |
// Declaración de los pines de la pantalla OLED | |
#define OLED_MOSI 3 | |
#define OLED_CLK 2 | |
#define OLED_DC 5 | |
#define OLED_CS 6 | |
#define OLED_RESET 4 | |
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, | |
OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); | |
#define LOGO_HEIGHT 64 //Alto de la imagen a mostrar | |
#define LOGO_WIDTH 128 //Ancho de la imagen a mostrar | |
//Imagen generada en "http://javl.github.io/image2cpp/" | |
static const unsigned char PROGMEM logo_bmp[] = | |
{ | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x60, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x90, 0x01, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0xff, 0xf8, 0xf4, 0x00, 0x00, 0x20, 0x00, 0x00, 0x70, | |
0x3f, 0xff, 0x80, 0x70, 0x03, 0xfc, 0x7f, 0xff, 0xff, 0xfe, 0xff, 0xe0, 0xff, 0xf8, 0xf0, 0xf8, | |
0x7f, 0xff, 0xc0, 0xf8, 0x07, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xf9, 0xf8, | |
0x7f, 0xff, 0xc1, 0xf8, 0x0f, 0xff, 0xff, 0xff,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0xfc, 0xff, 0xf8, 0xff, 0xfc, | |
0x7f, 0xff, 0xff, 0x1f, 0xdf, 0xff, 0xff, 0xfc, 0x1f, 0xf1, 0xfc, 0x7c, 0xff, 0xfc, 0xfd, 0xfe, | |
0x7f, 0xff, 0xfe, 0x1f, 0xcf, 0xff, 0xff, 0xfc, 0x1f, 0xf1, 0xfc, 0x7e, 0xff, 0xfd, 0xf9, 0xfe, | |
0x7f, 0xff, 0xfe, 0x1f, 0xe7, 0xfe, 0xff, 0xfc, 0x0f, 0xf1, 0xfe, 0x3e, 0xff, 0xf9, 0xf0, 0xf8, | |
0x3b, 0xff, 0x9c, 0x0e, 0xc1, 0xfc, 0x7f, 0xfc, 0x0f, 0xe3, 0xff, 0x1c, 0x7f, 0xf0, 0xe0, 0x70, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x03, 0xf0, 0x00, 0x01, 0xd9, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x18, 0x08, 0x00, 0x00, 0x0c, 0x81, 0xbf, 0xc0, 0x07, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x18, 0x0f, 0xfb, 0xfb, 0x8f, 0xe3, 0xff, 0xee, 0x0f, 0xf9, 0xfc, 0xef, 0xf7, 0xf0, 0x00, | |
0x00, 0x01, 0x45, 0xfc, 0xe6, 0x8b, 0x9a, 0xe7, 0xbb, 0x0b, 0xea, 0x7a, 0xab, 0xf9, 0xc8, 0x00, | |
0x00, 0x01, 0x45, 0xe5, 0xbe, 0xfa, 0x8e, 0xef, 0x9b, 0x0b, 0x6a, 0xfe, 0xab, 0xcb, 0xf0, 0x00, | |
0x00, 0x01, 0x45, 0x65, 0x1a, 0x03, 0xb2, 0xef, 0x9b, 0x1b, 0x2a, 0xe2, 0xa8, 0xc4, 0x08, 0x00, | |
0x00, 0x01, 0x45, 0xf5, 0xf6, 0xfa, 0xbc, 0xef, 0x9b, 0xfb, 0xea, 0xfa, 0xab, 0xef, 0xe8, 0x00, | |
0x00, 0x01, 0x44, 0x0c, 0x0a, 0x8a, 0xb6, 0xe0, 0x38, 0x18, 0x0a, 0x02, 0xa8, 0x18, 0x18, 0x00, | |
0x00, 0x01, 0x87, 0xfb, 0xf9, 0x86, 0x67, 0x9f, 0xff, 0xf7, 0xf1, 0xfc, 0xcf, 0xf7, 0xf0, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x80, 0xff, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x06, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x90, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |
}; | |
void setup() { | |
Serial.begin(9600); | |
// Inializando el OLED | |
if(!display.begin(SSD1306_SWITCHCAPVCC)) { | |
Serial.println(F("el modulo fallo")); | |
for(;;); //No hace nada, bucle permanente | |
} | |
} | |
void loop() { | |
/*testdrawbitmap(logo_bmp,128, 64); // Muestra imagen | |
// Invierte los colores | |
display.invertDisplay(true); | |
delay(2000); | |
display.invertDisplay(false); | |
delay(2000);*/ | |
testdrawstyles("HELLO WORLD"); // Muestra texto | |
delay(2000); | |
} | |
void testdrawstyles(String texto) { | |
display.clearDisplay(); // Limpia la pantalla | |
display.setTextSize(1); // Tamaño del texto | |
display.setTextColor(WHITE); // Color del texto | |
display.setCursor(0,32); // Coordenadas de inicio del texto | |
display.println(texto); | |
display.display(); // Muestra el texto con las configuraciones dadas | |
} | |
void testdrawbitmap(const uint8_t *imagen, int16_t ancho, int16_t alto) { | |
display.clearDisplay(); // Limpia la pantalla | |
display.drawBitmap( // Dibuja Imagen | |
(display.width() - ancho ) / 2, | |
(display.height() - alto) / 2, | |
imagen, ancho, alto, 1); | |
display.display(); // Muestra el texto con las configuraciones dadas | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define ledA 7 | |
const byte pinObstaculo = 8; | |
int hayObstaculo = HIGH; | |
int val = 0; | |
void setup() { | |
Serial.begin(9300); | |
pinMode(ledA , OUTPUT); | |
} | |
void loop() { | |
hayObstaculo = digitalRead(pinObstaculo); | |
if (hayObstaculo == LOW){ | |
Serial.println("Obstaculo Detectado!!"); | |
digitalWrite(ledA, HIGH); | |
} | |
else{ | |
Serial.println("Despejado"); | |
digitalWrite(ledA, LOW); | |
} | |
delay(20); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment