Last active
June 1, 2019 20:38
-
-
Save Adobe-Android/1f11d5329b2f80c92729f30676bc528b to your computer and use it in GitHub Desktop.
My Arduino Software Collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
void setup() | |
{ | |
Wire.begin(); | |
Serial.begin(115200); | |
Serial.println("\nI2C Scanner"); | |
} | |
void loop() | |
{ | |
byte error, address; | |
int nDevices; | |
Serial.println("Scanning..."); | |
nDevices = 0; | |
for (address = 1; address < 127; address++) | |
{ | |
Wire.beginTransmission(address); | |
error = Wire.endTransmission(); | |
if (error == 0) | |
{ | |
Serial.print("I2C device found at address 0x"); | |
if (address < 16) | |
{ | |
Serial.print("0"); | |
} | |
Serial.println(address, HEX); | |
nDevices++; | |
} | |
else if (error == 4) | |
{ | |
Serial.print("Unknow error at address 0x"); | |
if (address < 16) | |
{ | |
Serial.print("0"); | |
} | |
Serial.println(address, HEX); | |
} | |
} | |
if (nDevices == 0) | |
{ | |
Serial.println("No I2C devices found\n"); | |
} | |
else | |
{ | |
Serial.println("done\n"); | |
} | |
delay(5000); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LiquidCrystal_I2C.h> | |
#include <Wire.h> | |
// set the LCD number of columns and rows | |
int lcdColumns = 20; | |
int lcdRows = 4; | |
// set LCD address, number of columns and rows | |
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows); | |
void setup() | |
{ | |
// initialize LCD | |
lcd.init(); | |
// turn on LCD backlight | |
lcd.backlight(); | |
Wire.begin(); | |
Serial.begin(115200); | |
Serial.println("\nI2C Scanner"); | |
} | |
void loop() | |
{ | |
char test[] = "Hello, World!"; | |
int col = 4; | |
// set cursor to a variable column, first row | |
lcd.setCursor(col, 0); | |
// print message | |
lcd.print(test); | |
delay(1000); | |
// clears the display to print new message | |
lcd.clear(); | |
lcd.setCursor(col, 1); | |
lcd.print(test); | |
delay(1000); | |
lcd.clear(); | |
lcd.setCursor(col, 2); | |
lcd.print(test); | |
delay(1000); | |
lcd.clear(); | |
lcd.setCursor(col, 3); | |
lcd.print(test); | |
delay(1000); | |
lcd.clear(); | |
int counter = char_counter(test); | |
Serial.println(counter); | |
lcd.setCursor(5, 1); | |
lcd.print("Line count"); | |
delay(1000); | |
lcd.setCursor(7, 2); | |
lcd.print("is"); | |
delay(1000); | |
lcd.setCursor(11, 2); | |
lcd.print(String(counter)); | |
delay(1000); | |
lcd.clear(); | |
} | |
int char_counter(char *character_arr) | |
{ | |
int char_length = strlen(character_arr); | |
return char_length; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Hello World OLED Test */ | |
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"` | |
SSD1306 display(0x3c, 5, 4); // Initialise the OLED display using Wire library | |
void setup() | |
{ | |
Serial.begin(115200); | |
display.init(); // Initialising the UI will init the display too. | |
display.flipScreenVertically(); | |
display.clear(); | |
} | |
void loop() | |
{ | |
drawHelloWorld(); | |
display.display(); | |
display.clear(); | |
delay(2000); | |
display.display(); | |
delay(3000); | |
} | |
void drawHelloWorld() | |
{ | |
char i[]{"Hello, world!"}; | |
display.setTextAlignment(TEXT_ALIGN_LEFT); | |
display.setFont(ArialMT_Plain_10); | |
display.drawString(0, 0, i); | |
display.setFont(ArialMT_Plain_16); | |
display.drawString(0, 10, i); | |
display.setFont(ArialMT_Plain_24); | |
display.drawString(0, 26, i); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int led = 5; | |
const int button = 16; | |
int temp = 0; | |
void setup() | |
{ | |
Serial.begin(9600); | |
pinMode(led, OUTPUT); | |
pinMode(button, INPUT); | |
digitalWrite(led, LOW); | |
} | |
void loop() | |
{ | |
temp = digitalRead(button); | |
if (temp == HIGH) | |
{ | |
digitalWrite(led, HIGH); | |
Serial.println("LED Turned ON"); | |
delay(200); | |
} | |
else | |
{ | |
digitalWrite(led, LOW); | |
Serial.println("LED Turned OFF"); | |
delay(200); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment