source: rtos_arduino/trunk/arduino_lib/libraries/TFT/examples/Arduino/TFTColorPicker/TFTColorPicker.ino@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 1.4 KB
Line 
1/*
2
3 TFT Color Picker
4
5 This example for the Arduino screen reads the input of
6 potentiometers or analog sensors attached to A0, A1,
7 and A2 and uses the values to change the screen's color.
8
9 This example code is in the public domain.
10
11 Created 15 April 2013 by Scott Fitzgerald
12
13 http://arduino.cc/en/Tutorial/TFTColorPicker
14
15 */
16
17// pin definition for the Uno
18#define cs 10
19#define dc 9
20#define rst 8
21
22// pin definition for the Leonardo
23// #define cs 7
24// #define dc 0
25// #define rst 1
26
27#include <TFT.h> // Arduino LCD library
28#include <SPI.h>
29
30TFT TFTscreen = TFT(cs, dc, rst);
31
32void setup() {
33 // begin serial communication
34 Serial.begin(9600);
35
36 // initialize the display
37 TFTscreen.begin();
38
39 // set the background to white
40 TFTscreen.background(255, 255, 255);
41
42}
43
44void loop() {
45
46 // read the values from your sensors and scale them to 0-255
47 int redVal = map(analogRead(A0), 0, 1023, 0, 255);
48 int greenVal = map(analogRead(A1), 0, 1023, 0, 255);
49 int blueVal = map(analogRead(A2), 0, 1023, 0, 255);
50
51 // draw the background based on the mapped values
52 TFTscreen.background(redVal, greenVal, blueVal);
53
54 // send the values to the serial monitor
55 Serial.print("background(");
56 Serial.print(redVal);
57 Serial.print(" , ");
58 Serial.print(greenVal);
59 Serial.print(" , ");
60 Serial.print(blueVal);
61 Serial.println(")");
62
63 // wait for a moment
64 delay(33);
65
66}
67
Note: See TracBrowser for help on using the repository browser.