반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리

[Arduino] LCD and 7 Segment

2017. 1. 10. 09:27 | Posted by 솔웅


반응형


※  Control LCD with illuminance sencor



Circuit




Source Code


LiquidCrystal Library. This library allows an Arduino board to control LiquidCrystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs.


include LiquidCrystal Library.




#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,2,3,4,5);

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16,2);
  lcd.print("More Fun Life");
  Serial.print("Test");
}

void loop() {
  // put your main code here, to run repeatedly:
  lcd.setCursor(0,1);
  lcd.print(analogRead(A0));
  delay(200);
}


==> Display Illuminance sensor value on LCD



※ Control LCD using ultrasonic sencor


Circuit




Source Code


#include <LiquidCrystal.h>
#define TRIG 8
#define ECHO 9

LiquidCrystal lcd(12,11,2,3,4,5);

void setup() {
  // put your setup code here, to run once:
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
  lcd.begin(16,2);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(TRIG, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);

  long distance = pulseIn(ECHO, HIGH)/58.2;
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(distance);
  lcd.print(" cm");
  delay(200);
}


refer to youtube tutorial (in Korean) : https://www.youtube.com/watch?v=coFwvg_O1q4&index=8&list=PL0Vl139pNHbe-JlsydLg3NFRk6nC_cC7w




7 Segment Anode


7 Segment Cathode




※ 7 Segment



Circuit



Source Code


// Common Anode version
byte digits[10][7] =
{
  {0,0,0,0,0,0,1 }, // display '0'
  {1,0,0,1,1,1,1 }, // display '1'
  {0,0,1,0,0,1,0 }, // display '2'
  {0,0,0,0,1,1,0 }, // display '3'
  {1,0,0,1,1,0,0 }, // display '4'
  {0,1,0,0,1,0,0 }, // display '5'
  {0,1,0,0,0,0,0 }, // display '6'
  {0,0,0,1,1,1,1 }, // display '7'
  {0,0,0,0,0,0,0 }, // display '8'
  {0,0,0,1,1,0,0 }  // display '9'
};

// Common Cathode version
/*
byte digits[10][7] = {
  {1,1,1,1,1,1,0 }, // display '0'
  {0,1,1,0,0,0,0 }, // display '1'
  {1,1,0,1,1,0,1 }, // display '2'
  {1,1,1,1,0,0,1 }, // display '3'
  {0,1,1,0,0,1,1 }, // display '4'
  {1,0,1,1,0,1,1 }, // display '5'
  {1,0,1,1,1,1,1 }, // display '6'
  {1,1,1,0,0,0,0 }, // display '7'
  {1,1,1,1,1,1,1 }, // display '8'
  {1,1,1,0,0,1,1 }  // display '9'
};
*/
void setup() {
  // put your setup code here, to run once:
  for(int i=2;i<10;i++) {
    pinMode(i,OUTPUT);
  }
  digitalWrite(9,HIGH); // turn off DP LED
}

void loop() {
  // put your main code here, to run repeatedly:
  for(int i=0; i<10;i++) {
    delay(1000);
    displayDigit(i);
  }
}

void displayDigit(int num) {
  int pin = 2;
  for(int i=0; i<7; i++) {
    digitalWrite(pin+i, digits[num][i]);
  }
}



※ 7 Segment with buttons


Circuit


Source Code


#define PLUS 11
#define MINUS 12

int digit = 0;

// Common Anode version
byte digits[10][7] =
{
  {0,0,0,0,0,0,1 }, // display '0'
  {1,0,0,1,1,1,1 }, // display '1'
  {0,0,1,0,0,1,0 }, // display '2'
  {0,0,0,0,1,1,0 }, // display '3'
  {1,0,0,1,1,0,0 }, // display '4'
  {0,1,0,0,1,0,0 }, // display '5'
  {0,1,0,0,0,0,0 }, // display '6'
  {0,0,0,1,1,1,1 }, // display '7'
  {0,0,0,0,0,0,0 }, // display '8'
  {0,0,0,1,1,0,0 }  // display '9'
};

void setup() {
  // put your setup code here, to run once:
  pinMode(PLUS,INPUT);
  pinMode(MINUS, INPUT);

  for(int i=2;i<10;i++) {
    pinMode(i,OUTPUT);
  }
  digitalWrite(9,HIGH); // turn off DP LED
}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(PLUS) == HIGH)
  {
    ++digit;
    if(digit > 9)
    {
      digit=0;
    }
  }

  if(digitalRead(NINUS) == HIGH)
  {
    --digit;
    if(digit < 0)
    {
      digit=9;
    }
  } 

  displayDigit(digit);
  delay(100);
}

void displayDigit(int num) {
  int pin = 2;
  for(int i=0; i<7; i++) {
    digitalWrite(pin+i, digits[num][i]);
  }
}


refer to youtube tutorial (in Korean) : https://www.youtube.com/watch?v=SRtYpBnmPfA&index=9&list=PL0Vl139pNHbe-JlsydLg3NFRk6nC_cC7w

반응형