MdelgadoL
3 years ago
commit
fdd1d74848
2 changed files with 140 additions and 0 deletions
After Width: | Height: | Size: 61 KiB |
@ -0,0 +1,140 @@ |
|||
|
|||
#include <SPI.h> |
|||
#include <Wire.h> |
|||
#include <Adafruit_GFX.h> |
|||
#include <Adafruit_SSD1306.h> |
|||
|
|||
//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<potNumber;x++){ |
|||
display.setCursor(0, 0); |
|||
display.print("POT"); |
|||
display.print(x); |
|||
display.print(" = "); |
|||
int p1=analogRead(pots[x]); |
|||
p1=map(p1,0,5000,1,maxPot[x]); |
|||
display.println(p1); |
|||
} |
|||
/* display.print("POT1 = ");
|
|||
int p1=analogRead(A1); |
|||
p1=map(p1,0,5000,1,255); |
|||
display.println(p1); |
|||
*/display.setCursor(60, 0); |
|||
display.print("POT2 = "); |
|||
int p2=analogRead(A2); |
|||
p2=map(p2,0,5000,1,255); |
|||
display.println(p2); |
|||
display.setCursor(0, 10); |
|||
display.print("POT3 = "); |
|||
int p3=analogRead(A8); |
|||
p3=map(p3,0,5000,1,255); |
|||
display.println(p3); |
|||
display.setCursor(60, 10); |
|||
display.print("POT4 = "); |
|||
int p4=analogRead(A9); |
|||
p4=map(p4,0,5000,1,255); |
|||
display.println(p4); |
|||
display.setCursor(15, 25); |
|||
display.print(valor); |
|||
display.display(); |
|||
} |
|||
|
|||
|
|||
void ISR0(){ |
|||
start=!start; |
|||
delay(200); |
|||
} |
Loading…
Reference in new issue