需要准备的材料:

  1. Arduinio IDE
  2. Arduino开发板
  3. 馨品窗帘电机
  4. APDS-9960手势模块
  5. RS485 to TTL
  6. USB-TTL
  7. 杜邦线若干
  8. 串口工具

一、5110Nokia屏参考资料:

5110Nokia屏接线图:

5110屏驱动源代码:

#define PIN_SCE   7
#define PIN_RESET 6
#define PIN_DC    5
#define PIN_SDIN  4
#define PIN_SCLK  3// COnfiguration for the LCD
#define LCD_C     LOW
#define LCD_D     HIGH
#define LCD_CMD   0// Size of the LCD
#define LCD_X     84
#define LCD_Y     48int scrollPosition = -10;static const byte ASCII[][5] =
{
{0x00, 0x00, 0x00, 0x00, 0x00} // 20
,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #
,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $
,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %
,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &
,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '
,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (
,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )
,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *
,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +
,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,
,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -
,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .
,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f /
,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0
,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1
,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2
,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3
,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4
,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5
,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6
,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7
,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8
,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9
,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :
,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;
,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <
,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =
,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >
,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?
,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @
,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A
,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B
,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C
,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D
,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E
,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F
,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G
,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H
,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I
,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J
,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K
,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L
,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M
,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N
,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O
,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P
,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q
,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R
,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S
,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T
,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U
,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V
,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W
,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X
,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y
,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z
,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c &yen;
,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^
,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _
,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 `
,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a
,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b
,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c
,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d
,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e
,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f
,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g
,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h
,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i
,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j
,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k
,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l
,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m
,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n
,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o
,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p
,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q
,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r
,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s
,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t
,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u
,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v
,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w
,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x
,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y
,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z
,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b {
,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c |
,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d }
,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ←
,{0x00, 0x06, 0x09, 0x09, 0x06} // 7f →
};void LcdCharacter(char character)
{LcdWrite(LCD_D, 0x00);for (int index = 0; index < 5; index++){LcdWrite(LCD_D, ASCII[character - 0x20][index]);}LcdWrite(LCD_D, 0x00);
}void LcdClear(void)
{for (int index = 0; index < LCD_X * LCD_Y / 8; index++){LcdWrite(LCD_D, 0x00);}
}void LcdInitialise(void)
{pinMode(PIN_SCE,   OUTPUT);pinMode(PIN_RESET, OUTPUT);pinMode(PIN_DC,    OUTPUT);pinMode(PIN_SDIN,  OUTPUT);pinMode(PIN_SCLK,  OUTPUT);digitalWrite(PIN_RESET, LOW);digitalWrite(PIN_RESET, HIGH);LcdWrite(LCD_CMD, 0x21);  // LCD Extended Commands.LcdWrite(LCD_CMD, 0xBf);  // Set LCD Vop (Contrast). //B1LcdWrite(LCD_CMD, 0x04);  // Set Temp coefficent. //0x04LcdWrite(LCD_CMD, 0x14);  // LCD bias mode 1:48. //0x13LcdWrite(LCD_CMD, 0x0C);  // LCD in normal mode. 0x0d for inverseLcdWrite(LCD_C, 0x20);LcdWrite(LCD_C, 0x0C);
}void LcdString(char *characters)
{while (*characters){LcdCharacter(*characters++);}
}void LcdWrite(byte dc, byte data)
{digitalWrite(PIN_DC, dc);digitalWrite(PIN_SCE, LOW);shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);digitalWrite(PIN_SCE, HIGH);
}/**
* gotoXY routine to position cursor
* x - range: 0 to 84
* y - range: 0 to 5
*/
void gotoXY(int x, int y)
{LcdWrite( 0, 0x80 | x);  // Column.LcdWrite( 0, 0x40 | y);  // Row.
}void drawBox(void)
{int j;for(j = 0; j < 84; j++) // top{gotoXY(j, 0);LcdWrite(1, 0x01);}for(j = 0; j < 84; j++) //Bottom{gotoXY(j, 5);LcdWrite(1, 0x80);}for(j = 0; j < 6; j++) // Right{gotoXY(83, j);LcdWrite(1, 0xff);}for(j = 0; j < 6; j++) // Left{gotoXY(0, j);LcdWrite(1, 0xff);}
}void Scroll(String message)
{for (int i = scrollPosition; i < scrollPosition + 11; i++) { if ((i >= message.length()) || (i < 0)) { LcdCharacter(' '); } else { LcdCharacter(message.charAt(i)); } } scrollPosition++; if ((scrollPosition >= message.length()) && (scrollPosition > 0)){scrollPosition = -10;}
}/******字体展现功能实现模块******/
/*LcdString()实现字体固定显示*/
void setup(void)
{LcdInitialise();LcdClear();drawBox();gotoXY(7,1);LcdString("Nokia 5110");gotoXY(4,2);LcdString("Scroll Demo");
}/* Scroll();delay()实现字体循环转播*/
void loop(void)
{gotoXY(4,4);Scroll("for maore products please visit www.geeetech.com");delay(200);
}

二、APDS9960参考资料:

APDS9960接线:

GND GND
VCC 3.3V
SDA A4
SCL A5
INT 2

APDS9960驱动初始源代码:

#include <Wire.h>
#include <SparkFun_APDS9960.h>// Pins
#define APDS9960_INT    2 // Needs to be an interrupt pin// Constants// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
int isr_flag = 0;void setup() {// Initialize Serial portSerial.begin(9600);Serial.println();Serial.println(F("--------------------------------"));Serial.println(F("SparkFun APDS-9960 - GestureTest"));Serial.println(F("--------------------------------"));// Initialize interrupt service routineattachInterrupt(0, interruptRoutine, FALLING);// Initialize APDS-9960 (configure I2C and initial values)if ( apds.init() ) {Serial.println(F("APDS-9960 initialization complete"));} else {Serial.println(F("Something went wrong during APDS-9960 init!"));}// Start running the APDS-9960 gesture sensor engineif ( apds.enableGestureSensor(true) ) {Serial.println(F("Gesture sensor is now running"));} else {Serial.println(F("Something went wrong during gesture sensor init!"));}
}void loop() {if( isr_flag == 1 ) {handleGesture();isr_flag = 0;}
}void interruptRoutine() {isr_flag = 1;
}void handleGesture() {if ( apds.isGestureAvailable() ) {switch ( apds.readGesture() ) {case DIR_UP:Serial.println("UP");break;case DIR_DOWN:Serial.println("DOWN");break;case DIR_LEFT:Serial.println("LEFT");break;case DIR_RIGHT:Serial.println("RIGHT");break;case DIR_NEAR:Serial.println("NEAR");break;case DIR_FAR:Serial.println("FAR");break;default:Serial.println("NONE");}}
}

5110Nokia屏结合ADPS9960手势模块
功能整合后源代码:

#include <Wire.h>
#include <SparkFun_APDS9960.h>// Pins
#define APDS9960_INT    2 // Needs to be an interrupt pin// Constants// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
int isr_flag = 0;//5110******************************************
#define PIN_SCE   7
#define PIN_RESET 6
#define PIN_DC    5
#define PIN_SDIN  4
#define PIN_SCLK  3// COnfiguration for the LCD
#define LCD_C     LOW
#define LCD_D     HIGH
#define LCD_CMD   0// Size of the LCD
#define LCD_X     84
#define LCD_Y     48int scrollPosition = -10;static const byte ASCII[][5] =
{
{0x00, 0x00, 0x00, 0x00, 0x00} // 20
,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #
,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $
,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %
,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &
,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '
,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (
,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )
,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *
,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +
,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,
,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -
,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .
,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f /
,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0
,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1
,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2
,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3
,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4
,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5
,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6
,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7
,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8
,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9
,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :
,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;
,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <
,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =
,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >
,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?
,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @
,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A
,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B
,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C
,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D
,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E
,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F
,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G
,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H
,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I
,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J
,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K
,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L
,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M
,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N
,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O
,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P
,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q
,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R
,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S
,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T
,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U
,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V
,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W
,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X
,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y
,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z
,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c &yen;
,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^
,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _
,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 `
,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a
,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b
,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c
,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d
,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e
,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f
,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g
,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h
,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i
,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j
,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k
,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l
,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m
,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n
,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o
,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p
,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q
,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r
,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s
,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t
,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u
,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v
,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w
,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x
,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y
,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z
,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b {
,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c |
,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d }
,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ←
,{0x00, 0x06, 0x09, 0x09, 0x06} // 7f →
};void LcdCharacter(char character)
{LcdWrite(LCD_D, 0x00);for (int index = 0; index < 5; index++){LcdWrite(LCD_D, ASCII[character - 0x20][index]);}LcdWrite(LCD_D, 0x00);
}void LcdClear(void)
{for (int index = 0; index < LCD_X * LCD_Y / 8; index++){LcdWrite(LCD_D, 0x00);}
}void LcdInitialise(void)
{pinMode(PIN_SCE,   OUTPUT);pinMode(PIN_RESET, OUTPUT);pinMode(PIN_DC,    OUTPUT);pinMode(PIN_SDIN,  OUTPUT);pinMode(PIN_SCLK,  OUTPUT);digitalWrite(PIN_RESET, LOW);digitalWrite(PIN_RESET, HIGH);LcdWrite(LCD_CMD, 0x21);  // LCD Extended Commands.LcdWrite(LCD_CMD, 0xBf);  // Set LCD Vop (Contrast). //B1LcdWrite(LCD_CMD, 0x04);  // Set Temp coefficent. //0x04LcdWrite(LCD_CMD, 0x14);  // LCD bias mode 1:48. //0x13LcdWrite(LCD_CMD, 0x0C);  // LCD in normal mode. 0x0d for inverseLcdWrite(LCD_C, 0x20);LcdWrite(LCD_C, 0x0C);
}void LcdString(char *characters)
{while (*characters){LcdCharacter(*characters++);}
}void LcdWrite(byte dc, byte data)
{digitalWrite(PIN_DC, dc);digitalWrite(PIN_SCE, LOW);shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);digitalWrite(PIN_SCE, HIGH);
}/**
* gotoXY routine to position cursor
* x - range: 0 to 84
* y - range: 0 to 5
*/
void gotoXY(int x, int y)
{LcdWrite( 0, 0x80 | x);  // Column.LcdWrite( 0, 0x40 | y);  // Row.
}void drawBox(void)
{int j;for(j = 0; j < 84; j++) // top{gotoXY(j, 0);LcdWrite(1, 0x01);}for(j = 0; j < 84; j++) //Bottom{gotoXY(j, 5);LcdWrite(1, 0x80);}for(j = 0; j < 6; j++) // Right{gotoXY(83, j);LcdWrite(1, 0xff);}for(j = 0; j < 6; j++) // Left{gotoXY(0, j);LcdWrite(1, 0xff);}
}void Scroll(String message)
{for (int i = scrollPosition; i < scrollPosition + 11; i++) { if ((i >= message.length()) || (i < 0)) { LcdCharacter(' '); } else { LcdCharacter(message.charAt(i)); } } scrollPosition++; if ((scrollPosition >= message.length()) && (scrollPosition > 0)){scrollPosition = -10;}
}
// 5110**************************************************void interruptRoutine() {isr_flag = 1;
}void handleGesture() {if ( apds.isGestureAvailable() ) {switch ( apds.readGesture() ) {case DIR_UP:Serial.println("UP");break;case DIR_DOWN:Serial.println("DOWN");gotoXY(3,2);LcdString("***DOWN*** ");break;case DIR_LEFT:Serial.println("LEFT");gotoXY(3,2);LcdString("***LEFT ***");break;case DIR_RIGHT:Serial.println("RIGHT");gotoXY(3,2);LcdString("***RIGHT*** ");break;case DIR_NEAR:Serial.println("NEAR");gotoXY(3,2);LcdString("***NEAR*** ");break;case DIR_FAR:Serial.println("FAR");gotoXY(3,2);LcdString("***FAR*** ");break;default:Serial.println("NONE");gotoXY(3,2);LcdString("***NONE***");}
}
}void setup() {//****************5110显示模块的void setup()LcdInitialise();LcdClear();drawBox();
//  *****************************// Set interrupt pin as inputpinMode(APDS9960_INT, INPUT);// Initialize Serial portSerial.begin(9600);Serial.println();Serial.println(F("--------------------------------"));Serial.println(F("SparkFun APDS-9960 - GestureTest"));Serial.println(F("--------------------------------"));// Initialize interrupt service routineattachInterrupt(0, interruptRoutine, FALLING);// Initialize APDS-9960 (configure I2C and initial values)if ( apds.init() ) {Serial.println(F("APDS-9960 initialization complete"));} else {Serial.println(F("Something went wrong during APDS-9960 init!"));}// Start running the APDS-9960 gesture sensor engineif ( apds.enableGestureSensor(true) ) {Serial.println(F("Gesture sensor is now running"));} else {Serial.println(F("Something went wrong during gesture sensor init!"));}
}void loop() {if( isr_flag == 1 ) {detachInterrupt(0);handleGesture();isr_flag = 0;attachInterrupt(0, interruptRoutine, FALLING);}}

三、智馨尚品电动窗帘电机控制:

电机指令码组成:

其中我们以55 06 02 01 00 00 50 作为电机打开功能的示例
Ps:1.起始码在使用手册中默认
主机发送到窗帘电机为55
窗帘电机发送到主机为AA
2.电机地址码的查询和修改参照手册3.6和3.7
3.电机的命令码(功能实现)参照手册3.1、3.2和3.3
4.数据位一律为00 00

5.检校码需要通过如下公式计算:

即校验码= Byte 1 XOR Byte 2 XOR Byte3 XOR Byte 4 XOR Byte 5 XOR Byte 6
使用计算器进行计算:(windows+R+calc打开计算器)

以下是实现窗帘电机功能的串口指令码:

电机与RS485接线:

注意事项:

TXD RXD
RXD TXD
注意事项 TXD和RXD要交叉接

RS485与Arduino接线:
|

vcc 5v
TXD 8
RXD 10
GND GND

电机和5110屏及手势模块功能联动后源代码:


#include <Wire.h>
#include<SoftwareSerial.h>
#include <SparkFun_APDS9960.h>// Pins
#define APDS9960_INT    2 // Needs to be an interrupt pin// Constants// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
int isr_flag = 0;//5110******************************************
#define PIN_SCE   7
#define PIN_RESET 6
#define PIN_DC    5
#define PIN_SDIN  4
#define PIN_SCLK  3// COnfiguration for the LCD
#define LCD_C     LOW
#define LCD_D     HIGH
#define LCD_CMD   0// Size of the LCD
#define LCD_X     84
#define LCD_Y     48//窗帘电机和arduino接线
SoftwareSerial DLSerial(10, 8);  //10->tx, 8->rx。  分别接上设备的rx,tx //byte opencurtin[7]={85,06,02,01,00,00,80};//measured value 对应的为55 06 02 01 00 00 50
//byte closecurtin[7]={85,06,02,02,00,00,83};//measured value 对应的为55 06 02 02 00 00 53
//byte pausecurtin[7]={85,06,02,03,00,00,82};//measured value 对应的为55 06 02 03 00 00 52
byte opencurtin[7]={85,06,02,01,00,00,80};//measured value 对应的为55 06 02 01 00 00 50
byte closecurtin[7]={85,06,02,02,00,00,83};//measured value 对应的为55 06 02 02 00 00 53
byte pausecurtin[7]={85,06,02,03,00,00,82};//measured value 对应的为55 06 02 03 00 00 52 int scrollPosition = -10;static const byte ASCII[][5] =
{
{0x00, 0x00, 0x00, 0x00, 0x00} // 20
,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #
,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $
,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %
,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &
,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '
,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (
,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )
,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *
,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +
,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,
,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -
,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .
,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f /
,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0
,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1
,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2
,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3
,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4
,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5
,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6
,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7
,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8
,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9
,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :
,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;
,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <
,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =
,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >
,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?
,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @
,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A
,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B
,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C
,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D
,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E
,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F
,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G
,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H
,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I
,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J
,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K
,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L
,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M
,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N
,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O
,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P
,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q
,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R
,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S
,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T
,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U
,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V
,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W
,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X
,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y
,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z
,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c &yen;
,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^
,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _
,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 `
,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a
,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b
,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c
,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d
,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e
,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f
,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g
,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h
,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i
,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j
,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k
,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l
,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m
,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n
,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o
,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p
,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q
,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r
,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s
,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t
,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u
,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v
,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w
,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x
,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y
,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z
,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b {
,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c |
,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d }
,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ←
,{0x00, 0x06, 0x09, 0x09, 0x06} // 7f →
};void LcdCharacter(char character)
{LcdWrite(LCD_D, 0x00);for (int index = 0; index < 5; index++){LcdWrite(LCD_D, ASCII[character - 0x20][index]);}LcdWrite(LCD_D, 0x00);
}void LcdClear(void)
{for (int index = 0; index < LCD_X * LCD_Y / 8; index++){LcdWrite(LCD_D, 0x00);}
}void LcdInitialise(void)
{pinMode(PIN_SCE,   OUTPUT);pinMode(PIN_RESET, OUTPUT);pinMode(PIN_DC,    OUTPUT);pinMode(PIN_SDIN,  OUTPUT);pinMode(PIN_SCLK,  OUTPUT);digitalWrite(PIN_RESET, LOW);digitalWrite(PIN_RESET, HIGH);LcdWrite(LCD_CMD, 0x21);  // LCD Extended Commands.LcdWrite(LCD_CMD, 0xBf);  // Set LCD Vop (Contrast). //B1LcdWrite(LCD_CMD, 0x04);  // Set Temp coefficent. //0x04LcdWrite(LCD_CMD, 0x14);  // LCD bias mode 1:48. //0x13LcdWrite(LCD_CMD, 0x0C);  // LCD in normal mode. 0x0d for inverseLcdWrite(LCD_C, 0x20);LcdWrite(LCD_C, 0x0C);
}void LcdString(char *characters)
{while (*characters){LcdCharacter(*characters++);}
}void LcdWrite(byte dc, byte data)
{digitalWrite(PIN_DC, dc);digitalWrite(PIN_SCE, LOW);shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);digitalWrite(PIN_SCE, HIGH);
}/**
* gotoXY routine to position cursor
* x - range: 0 to 84
* y - range: 0 to 5
*/
void gotoXY(int x, int y)
{LcdWrite( 0, 0x80 | x);  // Column.LcdWrite( 0, 0x40 | y);  // Row.
}void drawBox(void)
{int j;for(j = 0; j < 84; j++) // top{gotoXY(j, 0);LcdWrite(1, 0x01);}for(j = 0; j < 84; j++) //Bottom{gotoXY(j, 5);LcdWrite(1, 0x80);}for(j = 0; j < 6; j++) // Right{gotoXY(83, j);LcdWrite(1, 0xff);}for(j = 0; j < 6; j++) // Left{gotoXY(0, j);LcdWrite(1, 0xff);}
}void Scroll(String message)
{for (int i = scrollPosition; i < scrollPosition + 11; i++) { if ((i >= message.length()) || (i < 0)) { LcdCharacter(' '); } else { LcdCharacter(message.charAt(i)); } } scrollPosition++; if ((scrollPosition >= message.length()) && (scrollPosition > 0)){scrollPosition = -10;}
}
// 5110**************************************************void interruptRoutine() {isr_flag = 1;
}void handleGesture() {if ( apds.isGestureAvailable() ) {switch ( apds.readGesture() ) {case DIR_UP:Serial.println("UP");break;case DIR_DOWN:Serial.println("DOWN");gotoXY(3,2);LcdString("***DOWN*** ");DLSerial.write(&pausecurtin[0],7);//发送停止指令到电机break;case DIR_LEFT:Serial.println("LEFT");gotoXY(3,2);LcdString("***LEFT ***");DLSerial.write(&opencurtin[0],7);//发送打开指令到电机break;case DIR_RIGHT:Serial.println("RIGHT");gotoXY(3,2);LcdString("***RIGHT*** ");DLSerial.write(&closecurtin[0],7);//发送关闭指令到电机break;case DIR_NEAR:Serial.println("NEAR");gotoXY(3,2);LcdString("***NEAR*** ");break;case DIR_FAR:Serial.println("FAR");gotoXY(3,2);LcdString("***FAR*** ");break;default:Serial.println("NONE");gotoXY(3,2);LcdString("***NONE***");}
}
}void setup() {DLSerial.begin(9600); //软串口初始化//****************5110显示模块的void setup()LcdInitialise();LcdClear();drawBox();
//  *****************************// Set interrupt pin as inputpinMode(APDS9960_INT, INPUT);// Initialize Serial portSerial.begin(9600);Serial.println();Serial.println(F("--------------------------------"));Serial.println(F("SparkFun APDS-9960 - GestureTest"));Serial.println(F("--------------------------------"));// Initialize interrupt service routineattachInterrupt(0, interruptRoutine, FALLING);// Initialize APDS-9960 (configure I2C and initial values)if ( apds.init() ) {Serial.println(F("APDS-9960 initialization complete"));} else {Serial.println(F("Something went wrong during APDS-9960 init!"));}// Start running the APDS-9960 gesture sensor engineif ( apds.enableGestureSensor(true) ) {Serial.println(F("Gesture sensor is now running"));} else {Serial.println(F("Something went wrong during gesture sensor init!"));}
}void loop() {if( isr_flag == 1 ) {detachInterrupt(0);handleGesture();isr_flag = 0;attachInterrupt(0, interruptRoutine, FALLING);}}

参考文档

有道云笔记:
//
https://note.youdao.com/web/#/file/621CD14A977B480EA6A191EE0CF9CB3F/note/WEBe175ef37a0fd6b7d42d836a550ab71f8/?search=apds
//
http://note.youdao.com/noteshare?id=5a4eaca49ec9a15c3e212eca9af182bc&sub=21C508F147434E87941A5D0FF80B7EDA

PS:由于尚未习惯使用博客的编译,其中许多文件未曾得以展示,如有不解之处,请参照我的笔记。

【Arduino】APDS9960S手势模块控制馨品窗帘电机并在5110屏中显示指令相关推荐

  1. Arduino人体红外模块控制

    Arduino人体红外模块控制 示例代码 /** Arduino UNO R3(或Arduino Nano)连接红外人体感应模块检测是否有人*/int irSensorPin = 3;//Arduin ...

  2. Arduino超声波测距模块控制蜂鸣器

    Arduino超声波测距模块控制蜂鸣器 超声波传感器 蜂鸣器 电路连接.接线 源码 超声波传感器 超声波传感器是利用超声波的特性研制而成的传感器.超声波是一种振动频 率高于声波的机械波,由换能晶片在电 ...

  3. Maps模块管理地图控件,用于在web页面中显示地图控件,提供各种接口操作地图控件,如添加标点、路线等。通过plus.maps可获取地图管理对象

    方法: openSysMap: 调用系统第三方程序进行导航 create: 创建Map对象 getMapById: 查找已经创建的Map对象 对象: Map: 地图控件对象 MapStyles: 地图 ...

  4. 智能家居硬件小制作(含源码)《手势识别控制器》基于PAJ7620手势模块、L298N驱动板、arduino

    智能家居硬件小制作(含源码)<手势识别控制器>基于PAJ7620手势模块.L298N驱动板.arduino 目录 智能家居硬件小制作(含源码)<手势识别控制器>基于PAJ762 ...

  5. 玩转Mixly – 3、Arduino AVR编程 之 控制

    以下内容源自Mixly官方技术文档: https://mixly.readthedocs.io/zh_CN/latest/Arduino/AVR/02Control.html 控制 控制类别中包括了时 ...

  6. 快速上手Arduino -- 打印超声波模块测距信息到OLED屏幕上

    文章目录 快速上手Arduino -- 打印超声波模块测距信息到OLED屏幕上 实现效果: 模块说明: 引脚接线方法: 程序源码 附录 快速上手Arduino – 打印超声波模块测距信息到OLED屏幕 ...

  7. 实践 基于Arduino 的 HC06蓝牙 控制 TB6612FNG 驱动电机

    一.实践目的 通过蓝牙模块控制电机的转动 这里用的是Arduino UNO 做主控版,最后搞定是这样的 二.HC06 蓝牙模块 HC06是常用的蓝牙从机模块,串口9600波特率,他有4个接口接入Ard ...

  8. 使用arduino D1 wifi模块(WeMos D1)连接阿里云物联网平台并成功实现APP点亮板载LED(九)---制作APP

    前几篇文章讲解了如何在阿里云控制台上给设备登记"身份证",如何用MQTT.fx客户端模拟一个设备连接阿里云物联网平台,分析了arduino编程环境如何配置依赖库,在arduino ...

  9. 4.0 树莓派做下位机播放视频、控制电机舵机、超声波检测、paj7620手势传感器控制,树莓派串口通信等程序分析

    文章目录 一.前言 二.Python实现封装打包自己写的代码 参考链接 我的参考 _init_.py setup.py 三. 树莓派的硬件解码播放器--Omxplayer 四.树莓派控制舵机,驱动L2 ...

最新文章

  1. iOS发布证书找不到了 回来整理一下
  2. [转]JAVA泛型通配符T,E,K,V区别,T以及ClassT,Class?的区别
  3. spark Tachyon
  4. 直播 | 天津大学副教授张长青:多模态融合的基础问题及算法研究
  5. php string pos,有关pos()的文章推荐10篇
  6. python封装c接口_用C为python3.1封装mysql接口(一)
  7. 计算机专业应届生年薪30多万,制造焦虑,非广告,请看截图
  8. 判断是否是合法的IP地址
  9. android反射改theme,全局修改默认字体,通过反射也能做到
  10. Linux之常用操作命令总结一
  11. 【C语言】实现 4阶(经典)龙格-库塔法 求解二阶微分方程
  12. php 修改文件的权限_授予PHP写入文件和文件夹的权限
  13. WPS2019 Ubuntu可以插入公式
  14. 企业微信第三方应用开发小白版
  15. 【清华AI自强计划-计算机视觉课程-第三讲课程笔记1】
  16. 儿童视力档案小程序开发,视力“云管家”
  17. mysql不小心删除root恢复
  18. win10打印服务器纸规格没有显示,win10系统打印机添加了自定义的纸张却找不到的操作办法...
  19. String的底层分析 (学习笔记)
  20. Bootstrap3基础 table-striped 表格实现隔行换色(浅灰色与白色交替)

热门文章

  1. elasticsearch线上调优[ Data too large]
  2. `Computer-Algorithm` 有向无环图DAG
  3. Python爬取360手机助手评论——以百度地图为例
  4. 读书是在丰富你,读你自己
  5. 蓝牙配对码配置错误_“看yellow 的时候,连错了蓝牙耳机,结果....”哈哈哈哈我笑到村里通网!!...
  6. 外贸跨境电商必备九款实用APP软件盘点,外贸人必看
  7. C++指针知识总结.
  8. 自己的服务解密,获取微信小程序用户的手机号码
  9. 翻译并添加 解析OV13850 datasheet
  10. Success diary