Skip to content

Instantly share code, notes, and snippets.

@ljahier
Created February 7, 2018 12:37
Show Gist options
  • Save ljahier/fff170ee8d0dd912ac3f045ec02f098d to your computer and use it in GitHub Desktop.
Save ljahier/fff170ee8d0dd912ac3f045ec02f098d to your computer and use it in GitHub Desktop.
// BY THEO FAUCHER
#include <Wire.h>
#include <SeeedOLED.h>
#include <SPI.h>
void setup()
{
Wire.begin();
SeeedOled.init(); //initialze SEEED OLED display
DDRB|=0x21;
PORTB |= 0x21;
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(0); // bit actif sur front montant de clock
SPI.setClockDivider(8); // clock initiale à 2,5MHz...
SPI.begin();
Serial.begin(115200);
SeeedOled.clearDisplay(); //clear the screen and set start position to top left corner
SeeedOled.setNormalDisplay(); //Set display to Normal mode
SeeedOled.setPageMode(); //Set addressing mode to Page Mode
SeeedOled.setTextXY(4,4); //Set the cursor to Xth Page, Yth Column
}
void ecritureOctet(int octet1, int octet2, int octet3)
{
SPI.transfer(octet1);
SPI.transfer(octet2);
SPI.transfer(octet3);
}
void loop()
{
int ValeurPotar = analogRead(A0);
int Tension = ValeurPotar*5/1023.0;
Serial.print(Tension);
Serial.print(" Volt");
if (Tension < 2) {
ecritureOctet(0, 255, 0);
Serial.print("Couleur: Vert");
SeeedOled.setTextXY(4,4);
SeeedOled.putString("Couleur: Vert");
}
if (Tension >= 2 && Tension < 4) {
ecritureOctet(255, 0, 0);
Serial.print("Couleur: Rouge");
SeeedOled.setTextXY(4,4);
SeeedOled.putString("Couleur: Rouge");
}
if (Tension >= 4) {
ecritureOctet(0, 0, 255);
Serial.print("Couleur: Bleu");
SeeedOled.setTextXY(4,4);
SeeedOled.putString("Couleur: Bleu");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment