극한의 아두이노 DIY생활 - 곡률측정기10

in kr-dev 커뮤니티2 years ago

안녕하세요 Jimae입니다.

저번에 setup 함수의 LCD 초기화 하는부분을 알고자 LCD 프로그램에 전부를 올리고 마무리 했었는대요.

그에 이어서 글을 써볼까합니다.

LCD 라이브러리 까지 올렸으니 example 꼭 참조하셨으면 합니다.

void LCDInit(void)
{
  lcd.begin();
  lcd.backlight();
  
  LCDSelect(1);
}

초기화 함수가 이것인대 사실 이것들은 전부 라이브러리 내부에 있는 프로그램들이라 이런식으로 초기화를 해주면 됩니다.

여기서 끝이에요.

void setup() {
    // put your setup code here, to run once:
  
    LCDInit();
    LightSensorInit();
    RotaryInit();
    SwitchInit();
    LightInit();

    Serial.begin (9600);
    
    LaserInit();
    
    MsTimer2::set(200, drawing); // flash함수를 200ms마다 호출한다
    MsTimer2::start();
}

다시 setup 함수를 돌아가자면 LCD초기화 끝난뒤 LightSensorInit() 함수를 부르는대 이것은 조도센서 입니다.

#include <SFE_TSL2561.h>
#include <Wire.h>


SFE_TSL2561 light;

boolean gain;     // Gain setting, 0 = X1, 1 = X16;
unsigned int ms;  // Integration ("shutter") time in milliseconds

void LightSensorInit(void)
{
  light.begin();

  unsigned char ID;
  
  if (light.getID(ID))
  {
    
  }
  else
  {
    byte error = light.getError();
  //  printError(error);
  }

  gain = 0;
  unsigned char time = 2;
//  Serial.println("Set timing...");
  light.setTiming(gain,time,ms);
//  Serial.println("Powerup...");
  light.setPowerUp();
}

double LightSensorRead(void)
{
  double lux = 0;    // Resulting lux value
  
   delay(ms);

  unsigned int data0, data1;

  if (light.getData(data0,data1))
  {
    // getData() returned true, communication was successful
 
    boolean good;  // True if neither sensor is saturated
    
    // Perform lux calculation:

    good = light.getLux(gain,ms,data0,data1,lux);
    
    // Print out the results:
  
  }
  else
  {
    // getData() returned false because of an I2C error, inform the user.

    byte error = light.getError();
//    printError(error);
  }

  return lux;
}

void printError(byte error)
  // If there's an I2C error, this function will
  // print out an explanation.
{
  Serial.print("I2C error: ");
  Serial.print(error,DEC);
  Serial.print(", ");
  
  switch(error)
  {
    case 0:
      Serial.println("success");
      break;
    case 1:
      Serial.println("data too long for transmit buffer");
      break;
    case 2:
      Serial.println("received NACK on address (disconnected?)");
      break;
    case 3:
      Serial.println("received NACK on data");
      break;
    case 4:
      Serial.println("other error");
      break;
    default:
      Serial.println("unknown error");
  }
}

예전에 스마트팜 식물관리용으로 만들었던 프로젝트에서 이걸사용한적 있습니다.

그것을 그대로 긁어와서 재사용했어요.

극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기1
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기2
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기3
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기4
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기5
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기6
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기7
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기8
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기9
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기10
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기11
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기12
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기13
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기14
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기15
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기16
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기17
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기18
극한의 아두이노 DIY생활 - 식물상태를 알려주는 기기19

그것은 이 시리즈에 정리되어있으니 참고 부탁드립니다.

그래서 조도센서도 마찬가지로 라이브러리를 사용하고 있기에

void LightSensorInit(void)
{
  light.begin();

  unsigned char ID;
  
  if (light.getID(ID))
  {
    
  }
  else
  {
    byte error = light.getError();
  //  printError(error);
  }

  gain = 0;
  unsigned char time = 2;
//  Serial.println("Set timing...");
  light.setTiming(gain,time,ms);
//  Serial.println("Powerup...");
  light.setPowerUp();
}

이걸로 똑같이 구현하면 됩니다.

오늘은 글이 길어져서 여기까지 쓰겠습니다.

다들 좋은 하루 되세요.

극한의 아두이노 DIY생활 - 곡률측정기1
극한의 아두이노 DIY생활 - 곡률측정기2
극한의 아두이노 DIY생활 - 곡률측정기3
극한의 아두이노 DIY생활 - 곡률측정기4
극한의 아두이노 DIY생활 - 곡률측정기5
극한의 아두이노 DIY생활 - 곡률측정기6
극한의 아두이노 DIY생활 - 곡률측정기7
극한의 아두이노 DIY생활 - 곡률측정기8
극한의 아두이노 DIY생활 - 곡률측정기9

Sort:  
 2 years ago 

[광고] STEEM 개발자 커뮤니티에 참여 하시면, 다양한 혜택을 받을 수 있습니다.

Coin Marketplace

STEEM 0.18
TRX 0.14
JST 0.029
BTC 57800.38
ETH 3127.30
USDT 1.00
SBD 2.40