메이킹

설계도를 기반으로 3D 프린터 제작과 코딩을 통해 가빈을 제작해 나간다.

기구물 3D 프린터

태양열 발전

::: 이미지 :::

::: 코드 :::

#include <SoftwareSerial.h>

int solar_input = A0; // 태양광 패널 인풋

void setup() {
    Serial.begin(9600);
    pinMode(solar_input, INPUT); // 태양광 전류 인풋
}

void loop() {
  
  int solar_value;
  solar_value = analogRead(solar_input);
  
  delay(1000);
  Serial.print(" salor panel = ");
  Serial.print(solar_value);
  Serial.print("\n");
  
}

디지털 디스플레이

::: 이미지 :::

::: 코드 :::

unsigned char LED_0F[] = 
{// 0 1  2   3 4 5  6   7 8 9  A   b C    d  E    F    -
  0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x8C,0xBF,0xC6,0xA1,0x86,0xFF,0xbf
};
unsigned char LED[4]; //用于LED的4位显示缓存
int SCLK = 2;
int RCLK = 1;
int DIO = 0; //这里定义了那三个脚
void setup ()
{
  pinMode(SCLK,OUTPUT);
  pinMode(RCLK,OUTPUT);
  pinMode(DIO,OUTPUT); //让三个脚都是输出状态
}
void loop()
{
  LED[0]=1;
  LED[1]=2;
  LED[2]=3;
  LED[3]=4;
  while(1)
  {
    LED4_Display ();
  } 

}

아두이노 코드

#include<SoftwareSerial.h>

int fan = 9;
int x = A0; // 태양광 패널 인풋
int a;
int b;
int c;
int d;

unsigned char LED_0F[] = 
{// 0 1  2   3 4 5  6   7 8 9  A   b C    d  E    F    -
  0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x8C,0xBF,0xC6,0xA1,0x86,0xFF,0xbf
};

unsigned char LED[4]; //用于LED的4位显示缓存

int SCLK = 2;
int RCLK = 1;
int DIO = 0; //这里定义了那三个脚
void setup ()
{
  Serial.begin(9600);
  pinMode(fan, OUTPUT); 
  pinMode(x, INPUT); // 태양광 전류 인풋
  pinMode(SCLK,OUTPUT);
  pinMode(RCLK,OUTPUT);
  pinMode(DIO,OUTPUT); //让三个脚都是输出状态
}

void loop()
{
  int x;
  int a;
  int b;
  int c;
  int d;
 
  a=floor(x);
  b=floor(x/10);
  c=floor(x/100);
  d=floor(x/1000);

  b=b%10;
  b=analogRead(b);

  delay(1);
  Serial.print(" a = ");
  Serial.print(a);

  x = analogRead(x);
  delay(1);

  Serial.print(" salor panel = ");
  Serial.print(x);

  a = analogRead(a);
  delay(1);

  Serial.print(" a = ");
  Serial.print(b);

  digitalWrite(fan, HIGH);
  delay(1);   // fan 100초 동안 가동

  LED[0]=a%10;
  LED[1]=b%10;
  LED[2]=c%10;
  LED[3]=d%10;

  while(1)
  {
    LED4_Display ();
  } 
}

void LED4_Display (void)
{
  unsigned char *led_table;          // 查表指针
  unsigned char i;
  //显示第1位
  led_table = LED_0F + LED[0];
  i = *led_table;

  LED_OUT(i); 
  LED_OUT(0x01); 
  digitalWrite(RCLK,LOW);
  digitalWrite(RCLK,HIGH);
  //显示第2位

  led_table = LED_0F + LED[1];
  i = *led_table;

  LED_OUT(i); 
  LED_OUT(0x02); 
    
  digitalWrite(RCLK,LOW);
  digitalWrite(RCLK,HIGH);

  //显示第3位

  led_table = LED_0F + LED[2];
  i = *led_table;
  LED_OUT(i); 
  LED_OUT(0x04); 

  digitalWrite(RCLK,LOW);
  digitalWrite(RCLK,HIGH);

  //显示第4位

  led_table = LED_0F + LED[3];
  i = *led_table;
    
  LED_OUT(i); 
  LED_OUT(0x08); 

  digitalWrite(RCLK,LOW);
  digitalWrite(RCLK,HIGH);

}

void LED_OUT(unsigned char X)
{
  unsigned char i;

  for(i=8;i>=1;i--)
  {
    if (X&0x80) 
    {
      digitalWrite(DIO,HIGH);
    }  
    else 
    {
      digitalWrite(DIO,LOW);
    }

    X<<=1;
    digitalWrite(SCLK,LOW);
    digitalWrite(SCLK,HIGH);
  }

}