commit fdd1d74848ed6ca046bf11d8533c83378d95790b Author: MdelgadoL Date: Fri Oct 15 09:20:24 2021 -0500 #1 Primera parte del codigo diff --git a/Diagramas/stm32f103-blue-pill-pinout.png b/Diagramas/stm32f103-blue-pill-pinout.png new file mode 100644 index 0000000..96f005d Binary files /dev/null and b/Diagramas/stm32f103-blue-pill-pinout.png differ diff --git a/ProfessionalLineFollower/ProfessionalLineFollower.ino b/ProfessionalLineFollower/ProfessionalLineFollower.ino new file mode 100644 index 0000000..21e3c36 --- /dev/null +++ b/ProfessionalLineFollower/ProfessionalLineFollower.ino @@ -0,0 +1,140 @@ + +#include +#include +#include +#include + +//PB11 SDA2 +//PB11 SCL2 +#define SCREEN_WIDTH 128 // OLED display width, in pixels +#define SCREEN_HEIGHT 32 // OLED display height, in pixels +#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin) +#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 +TwoWire WIRE2 (2,I2C_FAST_MODE); +#define Wire WIRE2 +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); +String valor; + +#define A0 PA0 +#define A1 PA1 //POT 1 DER +#define A2 PA2 //POT 2 DER +#define A3 PA3 +#define A4 PA4 +#define A5 PA5 +#define A6 PA6 +#define A7 PA7 +#define A8 PB1 //POT 1 IZQ +#define A9 PB0 //POT 2 IZQ + +#define button PB12 + +#define ledGreenLeft PA8 +#define ledRedLeft PA9 +#define ledBlueLeft PA10 +#define ledGreenRight PB5 +#define ledRedRight PB6 +#define ledBlueRight PB7 + +int pots[]={A1,A2,A8,A9}; //Pines de los potenciometros +int maxPot[]={100,100,100,100}; //Valores maximos a mapear los potenciometros +int potNumber=1; //cantidad de potenciometros + + +boolean start=false; + + +void setup() { + Serial.begin(115200); + + display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS); + display.display(); + delay(2000); // Pause for 2 seconds + display.clearDisplay(); + display.setTextSize(1); // Normal 1:1 pixel scale + display.setTextColor(SSD1306_WHITE); // Draw white text + + attachInterrupt(digitalPinToInterrupt(button), ISR0, RISING); + + pinMode(A1,INPUT); //POT + pinMode(A2,INPUT); //POT + pinMode(A3,OUTPUT); //S1 + pinMode(A4,OUTPUT); //S0 + pinMode(A5,INPUT); //SIGNAL + pinMode(A6,OUTPUT); //S2 + pinMode(A7,OUTPUT); //S3 + pinMode(A8,INPUT); //POT + pinMode(A9,INPUT); //POT + + pinMode(ledGreenLeft,OUTPUT); + pinMode(ledRedLeft,OUTPUT); + pinMode(ledBlueLeft,OUTPUT); + pinMode(ledBlueRight,OUTPUT); + pinMode(ledRedRight,OUTPUT); + pinMode(ledGreenRight,OUTPUT); + +} + +void loop() { + valor=""; + for(int x=0;x<16;x++){ + digitalWrite(A3,bitRead(x,1)); + digitalWrite(A4,bitRead(x,0)); + digitalWrite(A6,bitRead(x,2)); + digitalWrite(A7,bitRead(x,3)); + int v=analogRead(A5); + delay(1); + if(v>4000){ + valor+="0"; + }else{ + valor+="-"; + } + // Serial.print(v); + // Serial.print("\t"); + } + Serial.println(valor); + pantalla(valor); + + +} + +void pantalla(String valor){ + display.clearDisplay(); + display.setCursor(0, 0); + for(int x=0;x