查看: 3153|回复: 0

在pcduino上使用Color Image LCD Shield for Arduino

[复制链接]

该用户从未签到

发表于 2014-3-17 11:31:05 | 显示全部楼层 |阅读模式
分享到:
本帖最后由 Cherish. 于 2014-3-17 11:32 编辑

模块介绍
This 128×128 mini color LCD is a perfect match for the portable application. It is designed to repalce a broken screen in a cell phone. So the connector was not designed for multiple attachment/detachment. Please be gentle and handle with care.
This inexpensive LCD comes with a powerful white LED backlight and a relatively simple serial interface. It’s a 9-bit interface, so beware. But we were able to get the LCD up and running on a LPC2138 with a few hours worth of work.
Frame Dimensions: 1.35×1.58″ Active Display Dimensions: 1.2″x1.2″

QQ图片20140315192645.jpg
接线图
QQ图片20140316211851.jpg
接线要领:这个模块可以直接插在pcduino上。
演示代码
库下载地址:https://github.com/linksprite/Color-Image-LCD-Shield-For-Arduino
下载后解压压缩包重命名该文件夹为“NokiaLcd”,并放到arduino软件安装目录下的“libraries”目录下面,这个时候再启动arduinoIDE软件,就可以从“示例”里面看到这个库了。(注意:这个库里面的例程上的时钟不会走
如下图所示:
QQ图片20140316211308.jpg
  1. #include<NokiaLcd.h>

  2. // Enter the time below in 12-hr format
  3. #define HOURS 10
  4. #define MINUTES 21
  5. #define SECONDS 00
  6. #define AMPM 0  // enter 0 for AM, 1 for PM

  7. #define CLOCK_RADIUS 45  // radius of clock face
  8. #define CLOCK_CENTER 50  // If you adjust the radius, you'll probably want to adjust this
  9. #define H_LENGTH  25  // length of hour hand
  10. #define M_LENGTH  35  // length of minute hand
  11. #define S_LENGTH  43  // length of second hand

  12. #define BACKGROUND  BLACK  // room for growth, adjust the background color according to daylight
  13. #define C_COLOR  RED  // This is the color of the clock face, and digital clock
  14. #define H_COLOR  BLUE  // hour hand color
  15. #define M_COLOR  GREEN  // minute hand color
  16. #define S_COLOR  YELLOW  // second hand color

  17. PCF8833Lcd lcd = PCF8833Lcd(8,9,13,11);

  18. int hours, minutes, seconds, ampm;
  19. int buttonPins[3] = {3, 4, 5};

  20. void DrawClock(void)
  21. {
  22.   /* Draw the circle */
  23.   lcd.DrawCircle(CLOCK_CENTER, 66, CLOCK_RADIUS, C_COLOR);

  24.   /* Print 12, 3, 6, 9, a lot of arbitrary values are used here
  25.      for the coordinates. Just used trial and error to get them
  26.      into a nice position. */
  27.   lcd.PutStr("12", CLOCK_CENTER - CLOCK_RADIUS, 66-9, C_COLOR, BACKGROUND);
  28.   lcd.PutStr("3", CLOCK_CENTER - 9, 66 + CLOCK_RADIUS - 12, C_COLOR, BACKGROUND);
  29.   lcd.PutStr("6", CLOCK_CENTER + CLOCK_RADIUS - 18, 66-4, C_COLOR, BACKGROUND);
  30.   lcd.PutStr("9", CLOCK_CENTER - 9, 66 - CLOCK_RADIUS + 4, C_COLOR, BACKGROUND);
  31. }

  32. /*
  33.   displayAnalogTime() draws the three clock hands in their proper
  34.   position. Room for growth here, I'd like to make the clock hands
  35.   arrow shaped, or at least thicker and more visible.
  36. */
  37. void DisplayAnalogTime(int h, int m, int s)
  38. {
  39.   double midHours;  // this will be used to slightly adjust the hour hand
  40.   static int hx, hy, mx, my, sx, sy;

  41.   /* Adjust time to shift display 90 degrees ccw
  42.      this will turn the clock the same direction as text */
  43.   h -= 3;
  44.   m -= 15;
  45.   s -= 15;
  46.   if (h <= 0)
  47.     h += 12;
  48.   if (m < 0)
  49.     m += 60;
  50.   if (s < 0)
  51.     s += 60;

  52.   /* Delete old lines: */
  53.   lcd.DrawLine(CLOCK_CENTER, 66, CLOCK_CENTER+sx, 66+sy, BACKGROUND);  // delete second hand
  54.   lcd.DrawLine(CLOCK_CENTER, 66, CLOCK_CENTER+mx, 66+my, BACKGROUND);  // delete minute hand
  55.   lcd.DrawLine(CLOCK_CENTER, 66, CLOCK_CENTER+hx, 66+hy, BACKGROUND);  // delete hour hand

  56.   /* Calculate and draw new lines: */
  57.   s = map(s, 0, 60, 0, 360);  // map the 0-60, to "360 degrees"
  58.   sx = S_LENGTH * sin(3.14 * ((double) s)/180);  // woo trig!
  59.   sy = S_LENGTH * cos(3.14 * ((double) s)/180);  // woo trig!
  60.   lcd.DrawLine(CLOCK_CENTER, 66, CLOCK_CENTER+sx, 66+sy, S_COLOR);  // print second hand

  61.   m = map(m, 0, 60, 0, 360);  // map the 0-60, to "360 degrees"
  62.   mx = M_LENGTH * sin(3.14 * ((double) m)/180);  // woo trig!
  63.   my = M_LENGTH * cos(3.14 * ((double) m)/180);  // woo trig!
  64.   lcd.DrawLine(CLOCK_CENTER, 66, CLOCK_CENTER+mx, 66+my, M_COLOR);  // print minute hand

  65.   midHours = minutes/12;  // midHours is used to set the hours hand to middling levels between whole hours
  66.   h *= 5;  // Get hours and midhours to the same scale
  67.   h += midHours;  // add hours and midhours
  68.   h = map(h, 0, 60, 0, 360);  // map the 0-60, to "360 degrees"
  69.   hx = H_LENGTH * sin(3.14 * ((double) h)/180);  // woo trig!
  70.   hy = H_LENGTH * cos(3.14 * ((double) h)/180);  // woo trig!
  71.   lcd.DrawLine(CLOCK_CENTER, 66, CLOCK_CENTER+hx, 66+hy, H_COLOR);  // print hour hand
  72. }

  73. /*
  74.   displayDigitalTime() takes in values for hours, minutes, seconds
  75.   and am/pm. It'll print the time, in digital format, on the
  76.   bottom of the screen.
  77. */
  78. void DisplayDigitalTime(int h, int m, int s, int ap)
  79. {
  80.   char timeChar[12];

  81.   if (!ap)
  82.   {
  83.     sprintf(timeChar, "%.2d:%.2d:%.2d AM", h, m, s);
  84.   }
  85.   else
  86.   {
  87.     sprintf(timeChar, "%.2d:%.2d:%.2d PM", h, m, s);
  88.   }
  89.   /* Print the time on the clock */
  90.   lcd.PutStr(timeChar, CLOCK_CENTER + CLOCK_RADIUS + 4, 22, C_COLOR, BACKGROUND);
  91. }

  92. /*
  93.   setTime uses on-shield switches S1, S2, and S3 to set the time
  94.   pressing S3 will exit the function. S1 increases hours, S2
  95.   increases seconds.
  96. */
  97. void SetTime(void)
  98. {
  99.   /* Reset the clock to midnight */
  100.   seconds = 0;
  101.   minutes = 0;
  102.   hours = 12;
  103.   ampm = 0;

  104.   /* Draw the clock, so we can see the new time */
  105.   DrawClock();
  106.   DisplayAnalogTime(hours, minutes, seconds);
  107.   DisplayDigitalTime(hours, minutes, seconds, ampm);

  108.   while (!digitalRead(buttonPins[2]))
  109.     ;  // wait till they let go of S1

  110.   /* We'll run around this loop until S3 is pressed again */
  111.   while(digitalRead(buttonPins[2]))
  112.   {
  113.     /* If S1 is pressed, we'll update the hours */
  114.     if (!digitalRead(buttonPins[0]))
  115.     {
  116.       hours++;  // Increase hours by 1
  117.       if (hours == 12)
  118.         ampm ^= 1;  // Flip am/pm if it's 12 o'clock
  119.       if (hours >= 13)
  120.         hours = 1;  // Set hours to 1 if it's 13. 12-hour clock.

  121.       /* and update the clock, so we can see it */
  122.       DrawClock();
  123.       DisplayAnalogTime(hours, minutes, seconds);
  124.       DisplayDigitalTime(hours, minutes, seconds, ampm);
  125.     }
  126.     if (!digitalRead(buttonPins[1]))
  127.     {
  128.       minutes++;  // Increase minutes by 1
  129.       if (minutes >= 60)
  130.         minutes = 0;  // If minutes is 60, set it back to 0

  131.       /* and update the clock, so we can see it */
  132.       DrawClock();
  133.       DisplayAnalogTime(hours, minutes, seconds);
  134.       DisplayDigitalTime(hours, minutes, seconds, ampm);
  135.     }
  136.   }
  137.   /* Once S3 is pressed, we'll exit, but not until it's released */
  138.   while(!digitalRead(buttonPins[2]))
  139.     ;
  140. }

  141. void setup() {
  142.   // put your setup code here, to run once:
  143.   byte x;
  144.   byte y;

  145.   /* Set up the button pins as inputs, set pull-up resistor */
  146.   for (int i=0; i<3; i++)
  147.   {
  148.     pinMode(buttonPins[i], INPUT);
  149.     digitalWrite(buttonPins[i], HIGH);
  150.   }

  151.   hours = HOURS;
  152.   minutes = MINUTES;
  153.   seconds = SECONDS;
  154.   ampm = AMPM;

  155.   /* Initialize the LCD, set the contrast, clear the screen */
  156.   lcd.begin();
  157.   lcd.Contrast(-63);
  158.   lcd.ClearScring(BACKGROUND);

  159.   DrawClock();  // Draw the clock face, this includes 12, 3, 6, 9
  160.   DisplayAnalogTime(hours, minutes, seconds);  // Draw the clock hands
  161.   DisplayDigitalTime(hours, minutes, seconds, ampm);  // Draw the digital clock text

  162. }

  163. void loop() {
  164. /* We'll run around checking for button presses,
  165.      until it's been a second */
  166.   while(millis() % 1000)
  167.   {
  168.     if (!digitalRead(buttonPins[2]))
  169.       SetTime();  // If S3 was pressed, go set the time
  170.   }

  171.   /* We'll get here if it's been a second. We need to increase
  172.   seconds by 1 and then go from there */
  173.   seconds++;
  174.   if (seconds >= 60)
  175.   {
  176.     seconds = 0;  // If seconds is 60, set it back to 0
  177.     minutes++;    // and increase minutes by 1
  178.     if (minutes >= 60)
  179.     {
  180.       minutes = 0;  // If minutes is 60, set it back to 0
  181.       hours++;      // and increase hours by 1
  182.       if (hours == 12)
  183.         ampm ^= 1;  // If it's 12 o'clock, flip ampm
  184.       if (hours >= 13)
  185.         hours = 1;  // If hours is 13, set it to 1. 12-hr clock.
  186.     }
  187.   }
  188.   /* Once each second, we'll redraw the clock with new values */
  189.   DrawClock();
  190.   DisplayAnalogTime(hours, minutes, seconds);
  191.   DisplayDigitalTime(hours, minutes, seconds, ampm);
  192. }
复制代码
运行效果图:
QQ图片20140316212534.jpg
回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /5 下一条

手机版|小黑屋|与非网

GMT+8, 2024-12-21 19:15 , Processed in 0.123606 second(s), 17 queries , MemCache On.

ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

苏公网安备 32059002001037号

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.