by WingZero98579 » Tue Jul 03, 2012 12:28 am
OK i think i got it going so far. I had to put a delay of 400 in every LED cluster and remove the very last sensor delay. They are scrolling alot slower but it does work.
- Code: Select all
#define OLED_DC 11
#define OLED_CS 12
#define OLED_CLK 10
#define OLED_MOSI 9
#define OLED_RESET 13
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
int sensorPin = A0; // select the input pin for the potentiometer
//int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup(){
display.begin(SSD1306_SWITCHCAPVCC);
// init done
display.display(); // show splashscreen
delay(10);
display.clearDisplay(); // clears the screen and buffer
delay(10);
display.setTextSize(5);
display.setTextColor(WHITE);
display.println("KITT");
display.display();
delay(10);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
pinMode(1, OUTPUT);
pinMode(0, OUTPUT);
}
void loop()
{
// Read analog input:
sensorValue = analogRead(sensorPin);
// Scale input to width of display:
int w = map(sensorValue, 0, 1023, 0, display.width());
// Draw filled part of bar starting from left of screen:
display.fillRect(0, 0, w, display.height(), 1);
// Erase the area to the right of the bar:
display.fillRect(w, 0, display.width() - w, display.height(), 0);
// Update the screen:
display.display();
sensorValue = analogRead(sensorPin);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(2, HIGH);
delay(sensorValue);
delay(400);
sensorValue = analogRead(sensorPin);
digitalWrite(4, LOW);
digitalWrite(2, LOW);
digitalWrite(5, HIGH);
digitalWrite(1, HIGH);
delay(sensorValue);
delay(400);
sensorValue = analogRead(sensorPin);
digitalWrite(5, LOW);
digitalWrite(1, LOW);
digitalWrite(6, HIGH);
digitalWrite(0, HIGH);
delay(sensorValue);
delay(400);
sensorValue = analogRead(sensorPin);
digitalWrite(6, LOW);
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
digitalWrite(5, HIGH);
delay(sensorValue);
delay(400);
sensorValue = analogRead(sensorPin);
digitalWrite(1, LOW);
digitalWrite(5, LOW);
digitalWrite(2, HIGH);
digitalWrite(4, HIGH);
delay(sensorValue);
delay(400);
sensorValue = analogRead(sensorPin);
digitalWrite(2, LOW);
digitalWrite(4, LOW);
digitalWrite(3, HIGH);
}