/*
Example sketch DrawLogo.ino version 7.01.
From Kjell & Company's book "Hur funkar Arduino?" version 7.01.
From Kjell & Company's book "Hvordan virker Arduino?" version 7.01.
Using example code from the Universal 8bit Graphics Library
https://github.com/olikraus/u8glib/
This code is in the public domain.
*/
int sensorVal; // heltalsvärdet du får med analogRead på sensorn
int ledNr; //det antal pixlar du vill tända på ringen
// Include the Neopixel library
#include <Adafruit_NeoPixel.h>
// Declare and initialise global GPIO pin constant for Neopixel ring
const byte neoPin = 8;
// Declare and initialise global constant for number of pixels
const byte neoPixels = 16;
// Declare and initialise variable for Neopixel brightness
byte neoBright = 100;
// Create new Neopixel ring object
Adafruit_NeoPixel ring = Adafruit_NeoPixel(neoPixels, neoPin, NEO_GRB);
// Include the display library
#include "U8glib.h"
// Create new SSD1306 I2C display with 128x64 resolution
U8GLIB_SSD1306_128X64 oled(U8G_I2C_OPT_NONE);
// Declare and initialise global variables for display resolution
const int logo_width = 128;
const int logo_height = 64;
static unsigned char logo_bits[] U8G_PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x1f, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x1f, 0x00, 0x00, 0x0a, 0x15, 0x00, 0x3e, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xa0, 0x42, 0xaa, 0x1f, 0x00, 0x80, 0x3f, 0x3f, 0x80,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xc7, 0xbf, 0x1f, 0x00,
0x00, 0xbf, 0x1f, 0xc0, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
0xe7, 0x1f, 0x05, 0x00, 0x80, 0x9f, 0x1f, 0xc0, 0xf7, 0x03, 0x00, 0x00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, 0x7f, 0xff, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0xfc, 0xff, 0xf0, 0xf3, 0x57, 0xe5, 0xe7, 0x07, 0x3f,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xfe, 0xf0, 0xf3, 0x03,
0xe0, 0xe7, 0x07, 0x1f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc,
0xfc, 0xf0, 0xf3, 0x03, 0xf2, 0xf7, 0x07, 0x3f, 0x7f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xfe, 0xfc, 0xf9, 0xf3, 0xef, 0xf3, 0xf7, 0x03, 0xff,
0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfc, 0xf9, 0xf3, 0xff,
0xf3, 0xf3, 0x03, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe,
0xfc, 0xf9, 0xf1, 0xff, 0xf3, 0xf3, 0x03, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7e, 0xf8, 0xfb, 0xe1, 0xff, 0xf1, 0xf3, 0x03, 0xfe,
0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xf8, 0xff, 0xc1, 0xff,
0xf1, 0xf3, 0x03, 0xfe, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xfe, 0x01, 0x15, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1a, 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, 0x5d, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc0, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xf0, 0xff, 0xe3, 0x7f, 0xb0, 0xf1, 0xe1, 0xa3, 0xe3, 0x07, 0x3f, 0x1d,
0x17, 0x1f, 0x17, 0x76, 0xf8, 0xff, 0xf3, 0xff, 0xf0, 0xfb, 0xf3, 0xe7,
0xf7, 0x87, 0x7f, 0xbf, 0xdf, 0xbf, 0x1f, 0x7e, 0xf8, 0xff, 0xfb, 0xff,
0xf9, 0xff, 0xfb, 0xe7, 0xff, 0xcf, 0x7f, 0xbf, 0xff, 0xbf, 0x1f, 0x7f,
0xf8, 0xff, 0xfb, 0xff, 0xf9, 0xff, 0xff, 0xe7, 0xff, 0xcf, 0xff, 0xbf,
0xff, 0x3f, 0x1f, 0x7f, 0xfc, 0xbf, 0xfd, 0xff, 0xfb, 0xff, 0xff, 0xf7,
0xff, 0xcf, 0xff, 0x9f, 0xff, 0xbf, 0x9f, 0x3f, 0xfc, 0x03, 0xfc, 0xff,
0xfb, 0xff, 0xff, 0xf7, 0xff, 0xef, 0xff, 0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f, 0xff, 0x01, 0xfc, 0x7f, 0xfc, 0x7f,
0x7e, 0xfc, 0xf8, 0xfd, 0xfe, 0xf1, 0xef, 0xe7, 0xc7, 0x0f, 0xfe, 0x01,
0xf8, 0x7f, 0xf8, 0x3f, 0x7e, 0xfc, 0xfc, 0xfd, 0xfe, 0xe0, 0xef, 0xf7,
0xc7, 0x0f, 0xfe, 0x00, 0xe0, 0x17, 0xe0, 0x0f, 0x02, 0x04, 0x00, 0xfc,
0x78, 0xc0, 0x43, 0x20, 0x80, 0xc0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x7f, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e,
0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x1f, 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() {
// Initialise the ring
ring.begin();
ring.setBrightness(neoBright);
ring.show();
}
void loop(void) {
sensorVal=analogRead(A0); //läs av och spara värdet från sensorn
ledNr=map(sensorVal,0,1024,0,neoPixels); //mappa värdet på sensorVal till det antal pixlar du vill tända
// Turn on pixels from 0 to ledNr i blue
for(int i = 0; i < ledNr; i++){
ring.setPixelColor(i, ring.Color(0,0,189));
ring.show();
}
// Turn on pixels from ledNr to neoPixels in soft green
for(int i = ledNr; i < neoPixels; i++){
ring.setPixelColor(i, ring.Color(0,10,0));
ring.show();
}
// Refresh picture
oled.firstPage();
do {
draw();
} while(oled.nextPage());
delay(500);
}
void draw(void) {
// Set font to Helvetica size 10
oled.setFont(u8g_font_helvB10);
char buf1[22]; // 22 är antal tecken som får plats i buf1
sprintf (buf1, "SensorVal is: %d", sensorVal); //sprintf gör om heltalet sensorVal till %d, buf1 kan skrivas ut
oled.drawStr(0, 30, buf1); // Skriv ut buf1 en bit ner på skärmen
// Draw image om sensorvärdet är mindre än 200
if(sensorVal<200) oled.drawXBMP(0, 0, logo_width, logo_height, logo_bits);
}