-
Notifications
You must be signed in to change notification settings - Fork 0
/
instrumentasi_oled_sudut.ino
93 lines (73 loc) · 2.15 KB
/
instrumentasi_oled_sudut.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
asi#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
int a,b, adc, val[150];
long unsigned int adc_new = 0;
float sudut;
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
int batas = 100; //untuk rata2 adc sensor
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(30, 0);
display.clearDisplay();
display.println("HALO, SAYANG");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(45, 20);
display.println("INK");
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(50, 50);
display.println("sudut");
display.display();
delay(3000);
display.clearDisplay();
}
void loop() {
//-------Proses Akusisi Data ------------
adc_new = 0;
for (int i = 0; i < batas; i++) {
val[i] = analogRead(A0);
adc_new = adc_new + val[i];
delay(15);
}
// hasil akhir adc
adc = int(adc_new / batas);
//----persanamaan regresi liniar-----
sudut = 0.2917*adc + 25.09;
//------Buat Tampilan LCD ---------------
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 12);
display.clearDisplay();
display.println("Nilai adc:");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(65, 10);
display.println(adc);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 32);
display.println("sudut:");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(10, 42);
display.println(sudut);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(85, 45);
display.println("derajat");
display.display();
}