코코아팹은 누구나 창의적 아이디어를 현실로 만들어 낼 수 있도록
만들고, 공유하고, 배울 수 있는 터전이
되고자 합니다.
아이디와 비밀번호를 잊으셨나요?아이디 / 비밀번호 찾기
코코아팹 회원이 아니신가요? 회원가입
2015-01-07 11:13:57
NO | 부품명 | 수량 | 상세설명 |
1 | 오렌지보드 | 1 | 아두이노 |
2 | LCD | 1 | 16X2 LCD |
3 | SD카드 | 1 | SD카드 모듈 추가 |
4 | Push button | 1 | 상태 유지 버튼 |
5 | 택트 스위치 | 4 | 버튼 |
6 | Power plug | 1 | Arduino Power plug adapter cable |
7 | 가변저항 | 1 | 10KΩ 가변저항 |
8 | 10KΩ저항 | 4 | 저항 |
9 | 브레드보드 | 1 | 브레드보드 |
10 | 점퍼케이블 | 49 | 점퍼케이블 |
부품명 | 오렌지보드 | LCD | SD카드 모듈 | Push button | 택트 스위치 |
파트 |
부품명 | Power plug | 가변저항 | 10KΩ저항 | 브레드보드 | 점퍼케이블 |
파트 |
//Arduino Phone book v1.0 - By Gigi Butbaia #include <LiquidCrystal.h> #include <SD.h> LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // Define lcd int bUp = A0; // Define Up Button int bDown = A1; // Define Down Button int bLeft = A4; // Define Left Button int bEdit = A5; // edit/save button boolean editMode = false; // Edit Mode, activated when clicked edit Button File data; // File where all data is stored void setup() { //Configure LCD lcd.begin(16, 2); // Configure lcd as 8x2 lcd.clear(); // Clear display //Create Buttons pinMode(bUp, INPUT); // Up Button pinMode(bDown, INPUT); // Down Button pinMode(bLeft, INPUT); // Left Button //pinMode(bright, INPUT); pinMode(bEdit, INPUT); // Edit/Save Button pinMode(10, OUTPUT); if(!SD.begin(10)) { lcd.print("Error:"); lcd.setCursor(0,1); lcd.print("SD Card"); while(1); //todo edit } //data = SD.open("data.txt", FILE_WRITE); //data.println("TEST, SD CARD"); //data.close(); lcd.setCursor(0,0); lcd.print("Welcome"); delay(2000); lcd.clear(); data = SD.open("0.txt"); String dat = ""; while(data.available()) { dat += char(data.read()); } data.close(); if(dat != ":") { lcd.setCursor(0,0); lcd.print(getValue(dat, ':', 0)); lcd.setCursor(0, 1); lcd.print(getValue(dat, ':', 1)); lcd.setCursor(0,0); } } //index int i = 0; //Text int b = 0; //Cursor Pos int xcpos = 2; // xcpos - x cursor pos int xcpos2 = 0; //Configure Buttons int previousbUp = LOW; int previousbDown = LOW; int previousbLeft = LOW; int previousbEdit = LOW; //Create Array of characters char abc[54] = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; char num[12] = " 0123456789"; //Define two Strings for name and number String theData; String theNum; //Number and data will be stored in this string String fullData; //Define boolean to check if we are writing name or number boolean name = true; //Define int for screen position int scrpos = 0; void loop() { //Check if we are in editMode if(!editMode) { lcd.setCursor(0,0); if(digitalRead(bUp) == HIGH && previousbUp == LOW) { scrpos = 0; lcd.clear(); i++; lcd.print(i); lcd.setCursor(2, 0); //Convert int to char* char index[20]; String s = String(i) + ".txt"; s.toCharArray(index, 20); data = SD.open(index); String dat = ""; while(data.available()) { dat += char(data.read()); } data.close(); if(dat != ":") { lcd.print(getValue(dat, ':', 0)); lcd.setCursor(0, 1); lcd.print(getValue(dat, ':', 1)); lcd.setCursor(0,0); } previousbUp = HIGH; } else if(digitalRead(bUp) == LOW && previousbUp == HIGH) { previousbUp = LOW; } if(digitalRead(bDown) == HIGH && previousbDown == LOW) { scrpos = 0; lcd.clear(); i--; lcd.print(i); lcd.setCursor(2, 0); //Convert int to char* char index[20]; String s = String(i) + ".txt"; s.toCharArray(index, 20); data = SD.open(index); String dat = ""; while(data.available()) { dat += char(data.read()); } data.close(); if(dat != ":") { lcd.print(getValue(dat, ':', 0)); lcd.setCursor(0,1); lcd.print(getValue(dat, ':', 1)); lcd.setCursor(0,0); } previousbDown = HIGH; } else if(digitalRead(bDown) == LOW && previousbDown == HIGH) { previousbDown = LOW; } if(digitalRead(bLeft) == HIGH && previousbLeft == LOW) { scrpos++; lcd.scrollDisplayLeft(); if(scrpos > 3) { for(int i = 0; i < scrpos; i++) { lcd.scrollDisplayRight(); } scrpos = 0; } previousbLeft = HIGH; } else if(digitalRead(bLeft) == LOW && previousbLeft == HIGH) { previousbLeft = LOW; } if(digitalRead(bEdit) == HIGH && previousbEdit == LOW) { lcd.clear(); lcd.print("Edit"); lcd.setCursor(0,1); lcd.print("Mode"); char index[20]; String s = String(i) + ".txt"; s.toCharArray(index, 20); SD.remove(index); delay(2000); lcd.clear(); lcd.print(i); lcd.cursor(); previousbEdit = HIGH; lcd.setCursor(2,0); editMode = true; } else if(digitalRead(bEdit) == LOW && previousbEdit == HIGH) { previousbEdit = LOW; } } if(editMode) { //lcd.setCursor(xcpos, 0); if(!(xcpos > 15)) { lcd.setCursor(xcpos, 0); name = true; } else { lcd.setCursor(xcpos2, 1); name = false; /*if(xcpos2 > 7) { name = true; xcpos = 2; xcpos2 = 0; }*/ } if(digitalRead(bUp) == HIGH && previousbUp == LOW) { b++; if(name) { if(b > 52) { b = 0; } else if(b < 0) { b = 52; } lcd.print(abc[b]); } else { if(b > 10) { b = 0; } else if(b < 0) { b = 10; } lcd.print(num[b]); } previousbUp = HIGH; } else if(digitalRead(bUp) == LOW && previousbUp == HIGH) { previousbUp = LOW; } if(digitalRead(bDown) == HIGH && previousbDown == LOW) { b--; if(name) { if(b > 52) { b = 0; } else if(b < 0) { b = 52; } lcd.print(abc[b]); } else { if(b > 10) { b = 0; } else if(b < 0) { b = 10; } lcd.print(num[b]); } previousbDown = HIGH; } else if(digitalRead(bDown) == LOW && previousbDown == HIGH) { previousbDown = LOW; } if(digitalRead(bEdit) == HIGH && previousbEdit == LOW) { lcd.clear(); lcd.println("Saving.."); char index[20]; String s = String(i) + ".txt"; s.toCharArray(index, 20); data = SD.open(index, FILE_WRITE); fullData = theData + ":" + theNum; data.print(fullData); data.close(); delay(1200); lcd.clear(); i = 0; lcd.setCursor(0,0); lcd.print("0"); data = SD.open("0.txt"); lcd.setCursor(2, 0); String dat = ""; while(data.available()) { dat += char(data.read()); } data.close(); if(dat != ":") { lcd.print(getValue(dat, ':', 0)); lcd.setCursor(0,1); lcd.print(getValue(dat, ':', 1)); lcd.setCursor(0,0); } previousbEdit = HIGH; lcd.noCursor(); xcpos = 2; xcpos2 = 0; theData = ""; theNum = ""; b=0; editMode = false; } else if(digitalRead(bEdit) == LOW && previousbEdit == HIGH) { previousbEdit = LOW; } if(digitalRead(bLeft) == HIGH && previousbLeft == LOW) { //lcd.print(xcpos); if(name) { theData += abc[b]; //lcd.setCursor(0, 1); } else { theNum += num[b]; } //lcd.print(theData); if(!(xcpos > 15)) { xcpos++; lcd.setCursor(xcpos, 0); name = true; } else { xcpos2++; lcd.setCursor(xcpos2, 1); name = false; if(xcpos2 > 15) { lcd.scrollDisplayLeft(); //name = true; //xcpos = 2; //xcpos2 = 0; } } b = 0; previousbLeft = HIGH; } else if(digitalRead(bLeft) == LOW && previousbLeft == HIGH) { previousbLeft = LOW; } } } //Split received string from SD Card, for example data = AAA:BBB, getValue(data, ':', 0) = AAA, getValue(data, ':', 1) = BBB String getValue(String data, char separator, int index) { int found = 0; int strIndex[] = {0, -1}; int maxIndex = data.length()-1; for(int i=0; i<=maxIndex && found<=index; i++){ if(data.charAt(i)==separator || i==maxIndex){ found++; strIndex[0] = strIndex[1]+1; strIndex[1] = (i == maxIndex) ? i+1 : i; } } return found>index ? data.substring(strIndex[0], strIndex[1]) : ""; }
// 출처 : Instructables - Arduino phone book(Butbaia)
if(name) { theData += abc[b]; // 첫번째 줄에서는 알파벳을 입력합니다. } else { theNum += num[b]; // 두번째 줄에서는 숫자를 입력합니다. }
if(digitalRead(bUp) == HIGH && previousbUp == LOW) { scrpos = 0; lcd.clear(); i++; lcd.print(i); lcd.setCursor(2, 0); //Convert int to char* char index[20]; String s = String(i) + ".txt"; s.toCharArray(index, 20); data = SD.open(index); String dat = ""; while(data.available()) { dat += char(data.read()); } data.close(); if(dat != ":") { lcd.print(getValue(dat, ':', 0)); lcd.setCursor(0, 1); lcd.print(getValue(dat, ':', 1)); lcd.setCursor(0,0); } previousbUp = HIGH; } else if(digitalRead(bUp) == LOW && previousbUp == HIGH) { previousbUp = LOW; } if(digitalRead(bDown) == HIGH && previousbDown == LOW) { scrpos = 0; lcd.clear(); i--; lcd.print(i); lcd.setCursor(2, 0); //Convert int to char* char index[20]; String s = String(i) + ".txt"; s.toCharArray(index, 20); data = SD.open(index); String dat = ""; while(data.available()) { dat += char(data.read()); } data.close(); if(dat != ":") { lcd.print(getValue(dat, ':', 0)); lcd.setCursor(0,1); lcd.print(getValue(dat, ':', 1)); lcd.setCursor(0,0); } previousbDown = HIGH; }
판다마니아