Guest User

Untitled

a guest
Feb 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. // BY THEO FAUCHER
  2.  
  3. #include <Wire.h>
  4. #include <SeeedOLED.h>
  5. #include <SPI.h>
  6.  
  7. void setup()
  8. {
  9. Wire.begin();
  10. SeeedOled.init(); //initialze SEEED OLED display
  11. DDRB|=0x21;
  12. PORTB |= 0x21;
  13. SPI.setBitOrder(MSBFIRST);
  14. SPI.setDataMode(0); // bit actif sur front montant de clock
  15. SPI.setClockDivider(8); // clock initiale à 2,5MHz...
  16. SPI.begin();
  17. Serial.begin(115200);
  18. SeeedOled.clearDisplay(); //clear the screen and set start position to top left corner
  19. SeeedOled.setNormalDisplay(); //Set display to Normal mode
  20. SeeedOled.setPageMode(); //Set addressing mode to Page Mode
  21. SeeedOled.setTextXY(4,4); //Set the cursor to Xth Page, Yth Column
  22. }
  23.  
  24. void ecritureOctet(int octet1, int octet2, int octet3)
  25. {
  26. SPI.transfer(octet1);
  27. SPI.transfer(octet2);
  28. SPI.transfer(octet3);
  29. }
  30.  
  31. void loop()
  32. {
  33. int ValeurPotar = analogRead(A0);
  34. int Tension = ValeurPotar*5/1023.0;
  35. Serial.print(Tension);
  36. Serial.print(" Volt");
  37.  
  38. if (Tension < 2) {
  39. ecritureOctet(0, 255, 0);
  40. Serial.print("Couleur: Vert");
  41. SeeedOled.setTextXY(4,4);
  42. SeeedOled.putString("Couleur: Vert");
  43.  
  44. }
  45.  
  46. if (Tension >= 2 && Tension < 4) {
  47. ecritureOctet(255, 0, 0);
  48. Serial.print("Couleur: Rouge");
  49. SeeedOled.setTextXY(4,4);
  50. SeeedOled.putString("Couleur: Rouge");
  51.  
  52. }
  53.  
  54. if (Tension >= 4) {
  55. ecritureOctet(0, 0, 255);
  56. Serial.print("Couleur: Bleu");
  57. SeeedOled.setTextXY(4,4);
  58. SeeedOled.putString("Couleur: Bleu");
  59.  
  60. }
  61. }
Add Comment
Please, Sign In to add comment