#include<stdio.h>
#include<string.h>
int main() {
char str[1024] = "Hello Worl";
char c[2] = " d";
char d[10] = " x ";
char e[10] = " aaaab ";
strcat(str, c);
strcat(str, d);
strcat(str, e);
printf("%s\n", str); // Hello World
}
#include<stdio.h>
#include<string.h>
int main() {
char str[1024] = "Hello Worl";
char c[2] = " d";
char d[10] = " x ";
char e[10] = " aaaab ";
strcat(str, c);
strcat(str, d);
strcat(str, e);
printf("%s\n", str); // Hello World
}
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t time_val;
struct tm * pTime;
time(&time_val);
pTime = gmtime(&time_val);
pTime = localtime(&time_val);
printf("%d/%d/%d %d:%d:%d\n", pTime->tm_year + 1900, pTime->tm_mon + 1, pTime->tm_mday + 1,
pTime->tm_hour, pTime->tm_min, pTime->tm_sec);
}
apt-get install influxdb
influxd Execution
apt-get install influxdb-client
influx Execution (client Execution)
apt-get remove pakagename (ex apt-get remove mariadb-server)
#define GPIO_IN_1 PIN7_bp // PortJ
u16 state = 0;
bool debounce() {
state = (state<<1) | (PORTJ.IN & (1<<GPIO_IN_1)) | 0xfe00;
return (state == 0xff00);
}
int main(void)
{
while(1)
{
if (debounce())
{
//PORTJ.OUT = 0b00100000;
if(ADC_Arc_Hit == 0)
{
ADC_Arc_Hit = 1;
}
else
{
ADC_Arc_Hit = 0;
}
}
}
라즈베리파이에 GUI 화면 적용하고 시작시 GUI 화면으로 부팅시
command 입력창으로 이동 방법
Ctrl + Alt + F1 하면 터미널 창으로 전환 된다.
#include "button.h"
Button btn1;
#define LED_BUILTIN 5
//const int BUTTON_PIN = 12;
byte buttonState;
byte lastButtonState = LOW;
int ledState = LOW;
int ledStatecopy = LOW;
unsigned long previousMillis1 = 0;
const long interval1 = 500;
unsigned long previousMillis2 = 0;
const long interval2 = 100;
int i = 0;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(4, OUTPUT);
pinMode(15, OUTPUT);
btn1.begin(13);
}
void loop() {
unsigned long currentMillis1 = millis();
unsigned long currentMillis2 = millis();
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited long enough
// since the last press to ignore any noise:
if (btn1.debounce())
{
i++;
}
if (currentMillis1 - previousMillis1 >= interval1) {
previousMillis1 = currentMillis1;
if (ledState == LOW) {
ledState = HIGH; // Note that this switches the LED *off*
} else {
ledState = LOW; // Note that this switches the LED *on*
}
if(ledState == HIGH)
{
analogWrite(LED_BUILTIN, 45);
}
else
{
analogWrite(LED_BUILTIN, 0);
}
}
if (i >= 4)
{
i = 0;
}
if (currentMillis2 - previousMillis2 >= interval2) {
previousMillis2 = currentMillis2;
switch(i)
{
case 0:
analogWrite(4, 0); // analogRead 값은 0부터 1023까지, analogWrite 값은 0 부터 255까지
analogWrite(15, 0); // analogRead 값은 0부터 1023까지, analogWrite 값은 0 부터 255까지
break;
case 1:
analogWrite(4, 15); // analogRead 값은 0부터 1023까지, analogWrite 값은 0 부터 255까지 // 50
analogWrite(15, 50); // analogRead 값은 0부터 1023까지, analogWrite 값은 0 부터 255까지
break;
case 2:
analogWrite(4, 35); // analogRead 값은 0부터 1023까지, analogWrite 값은 0 부터 255까지 // 150
analogWrite(15, 150); // analogRead 값은 0부터 1023까지, analogWrite 값은 0 부터 255까지
break;
case 3:
analogWrite(4, 120); // analogRead 값은 0부터 1023까지, analogWrite 값은 0 부터 255까지 // 245
analogWrite(15, 245); // analogRead 값은 0부터 1023까지, analogWrite 값은 0 부터 255까지
break;
default:
break;
}
}
}
Button.h ===================================================
#ifndef button_h
#define button_h
#include "Arduino.h"
class Button
{
private:
uint8_t btn;
uint16_t state;
public:
void begin(uint8_t button) {
btn = button;
state = 0;
pinMode(btn, INPUT_PULLUP);
}
bool debounce() {
state = (state<<1) | digitalRead(btn) | 0xfe00;
return (state == 0xff00);
}
};
#endif
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
while (!Serial);
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.print(address,HEX);
Serial.println(" !");
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);
}