#include <TM1637Display.h>
#include <TM1637.h>
#define CLK 2
#define DIO 3
const int CLK1 = 4;
const int DIO1 = 5;
// joystick
int X;
int Y;
int PULSADOR = 6;
int SW;
//led bar
const int analogPin = A7; // the pin that the potentiometer is attached to
const int ledCount = 10; // the number of LEDs in the bar graph
int ledPins[] = {
21,20,19,18,17,16,15,14,0,1
};
TM1637 tm(CLK1, DIO1);
TM1637Display display(CLK, DIO);
uint8_t data1[] = {
SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G, //A
SEG_F | SEG_E | SEG_D, //L
SEG_A | SEG_F | SEG_G | SEG_E | SEG_D, //E
SEG_F | SEG_G | SEG_C | SEG_B | SEG_E //X
};
uint8_t data2[] = {
SEG_F | SEG_G | SEG_B | SEG_C | SEG_D, //Y
SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, //O
SEG_G, // -
SEG_G // -
};
uint8_t dataX[] = { // (+) X
SEG_E,
SEG_F | SEG_G | SEG_C | SEG_B | SEG_E,
SEG_C,
SEG_C,
};
uint8_t dataX1[] = { // (-) X
SEG_E,
SEG_G,
SEG_F | SEG_G | SEG_C | SEG_B | SEG_E,
SEG_C,
};
uint8_t dataY[] = { // (+) Y
SEG_E,
SEG_F | SEG_G | SEG_B | SEG_C | SEG_D,
SEG_C,
SEG_C,
};
uint8_t dataY1[] = { // (-) Y
SEG_E,
SEG_G,
SEG_F | SEG_G | SEG_B | SEG_C | SEG_D,
SEG_C,
};
uint8_t data0[] = { // (-) Y
SEG_G,
SEG_G,
SEG_G,
SEG_G,
};
void setup() {
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);}
tm.init();
tm.set(BRIGHT_TYPICAL);
display.setBrightness(5); // Set the display brightness (0-7)
// jostyck
}
void loop() {
X = analogRead(A0);
Y= analogRead(A1);
SW= digitalRead(PULSADOR);
if(SW == 1){
display.setSegments(data0);
}
if(SW == 0){
if( X > 520 && X <= 1023){
display.setSegments(dataX1);
} else{ }
if( X >=0 && X < 480 ){
display.setSegments(dataX);
}else{ }
if( Y >=0 && Y< 480 ){
display.setSegments(dataY1);
}else{ }
if( Y > 520 && Y <= 1023 ){
display.setSegments(dataY);
}else{ }
}
// read the potentiometer:
int sensorReading = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
// loop over the LED array:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
// if the array element's index is less than ledLevel,
// turn the pin for this element on:
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
// Force(1,2,3,4);
// Force(1,0,2,3);
}
//funciones
//dispaly B
void Force(int dat, int dat1, int dat2, int dat3){
// time
tm.display(0, dat);
tm.display(1, dat1);
tm.display(2, dat2);
tm.display(3, dat3);
delay(500);
}