-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
228 additions
and
7 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
examples/PMW3901_Framebuffer_LCD/PMW3901_Framebuffer_LCD.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include "Bitcraze_PMW3901.h" | ||
|
||
|
||
#include <Adafruit_GFX.h> // Core graphics library | ||
#include <Adafruit_ST7735.h> // Hardware-specific library | ||
//defines for TFT | ||
#define TFT_CS 9 | ||
#define TFT_RST 8 | ||
#define TFT_DC 7 | ||
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); | ||
int PixelScale = 3; | ||
|
||
|
||
// Using digital pin 10 for chip select | ||
Bitcraze_PMW3901 flow(10); | ||
char frame[35*35]; //array to hold the framebuffer | ||
|
||
const PROGMEM uint16_t ironhot[] = | ||
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0020,0x0020, | ||
0x0020,0x0020,0x0020,0x0841,0x0841,0x0841,0x0841, | ||
0x0841,0x0841,0x0861,0x0861,0x0861,0x0861,0x0861, | ||
0x1082,0x1082,0x1082,0x1082,0x1082,0x10a2,0x10a2, | ||
0x10a2,0x10a2,0x10a2,0x18c3,0x18c3,0x18c3,0x18c3, | ||
0x18c3,0x18e3,0x18e3,0x18e3,0x18e3,0x18e3,0x2104, | ||
0x2104,0x2104,0x2104,0x2104,0x2124,0x2124,0x2124, | ||
0x2124,0x2124,0x2124,0x2945,0x2945,0x2945,0x2945, | ||
0x2945,0x2965,0x2965,0x2965,0x2965,0x2965,0x3186, | ||
0x3186,0x3186,0x3186,0x31a6,0x31a6,0x31a6,0x31a6, | ||
0x31a6,0x39c7,0x39c7,0x39c7,0x39c7,0x39c7,0x39e7, | ||
0x39e7,0x39e7,0x39e7,0x39e7,0x4208,0x4208,0x4208, | ||
0x4208,0x4208,0x4228,0x4228,0x4228,0x4228,0x4228, | ||
0x4a49,0x4a49,0x4a49,0x4a49,0x4a49,0x4a69,0x4a69, | ||
0x4a69,0x4a69,0x4a69,0x528a,0x528a,0x528a,0x528a, | ||
0x528a,0x52aa,0x52aa,0x52aa,0x52aa,0x52aa,0x5acb, | ||
0x5acb,0x5acb,0x5acb,0x5acb,0x5aeb,0x5aeb,0x5aeb, | ||
0x5aeb,0x5aeb,0x630c,0x630c,0x630c,0x630c,0x630c, | ||
0x632c,0x632c,0x632c,0x632c,0x632c,0x632c,0x6b4d, | ||
0x6b4d,0x6b4d,0x6b4d,0x6b4d,0x6b6d,0x6b6d,0x6b6d, | ||
0x6b6d,0x6b6d,0x738e,0x738e,0x738e,0x738e,0x738e, | ||
0x73ae,0x73ae,0x73ae,0x73ae,0x73ae,0x7bcf,0x7bcf, | ||
0x7bcf,0x7bcf,0x7bcf,0x7bef,0x7bef,0x7bef,0x7bef, | ||
0x7bef,0x7bef,0x8410,0x8410,0x8410,0x8410,0x8410, | ||
0x8430,0x8430,0x8430,0x8430,0x8430,0x8c51,0x8c51, | ||
0x8c51,0x8c51,0x8c51,0x8c71,0x8c71,0x8c71,0x8c71, | ||
0x8c71,0x9492,0x9492,0x9492,0x9492,0x9492,0x94b2, | ||
0x94b2,0x94b2,0x94b2,0x9cd3,0x9cd3,0x9cd3,0x9cd3, | ||
0x9cd3,0x9cd3,0x9cf3,0x9cf3,0x9cf3,0x9cf3,0x9cf3, | ||
0xa514,0xa514,0xa514,0xa514,0xa514,0xa534,0xa534, | ||
0xa534,0xa534,0xa534,0xad55,0xad55,0xad55,0xad55, | ||
0xad55,0xad75,0xad75,0xad75,0xad75,0xb596,0xb596, | ||
0xb5b6,0xb5b6,0xb5b6,0xbdd7,0xbdd7,0xbdd7,0xbdf7, | ||
0xbdf7,0xbdf7,0xc618,0xc618,0xc638,0xc638,0xc638, | ||
0xce59,0xce59,0xce59,0xce79,0xce79,0xd69a,0xd69a, | ||
0xd69a,0xd6ba,0xd6ba,0xd6ba,0xdedb,0xdedb,0xdefb, | ||
0xdefb,0xdefb,0xe71c}; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
tft.initR(INITR_GREENTAB); // initialize a ST7735S chip, 144 is 1.44 in display | ||
tft.fillScreen(ST7735_BLACK); //Fill black | ||
tft.setRotation(3); //this specifies the rotation | ||
|
||
if (!flow.begin()) { | ||
Serial.println("Initialization of the flow sensor failed"); | ||
tft.fillScreen(ST7735_RED); | ||
delay(100); | ||
tft.fillScreen(ST7735_BLACK); //Flash screen red to indicate error | ||
delay(100); | ||
tft.fillScreen(ST7735_RED); | ||
while(1) { } | ||
} | ||
|
||
flow.enableFrameBuffer(); | ||
Serial.println("framebuffer init"); | ||
} | ||
|
||
|
||
void loop() { | ||
flow.readFrameBuffer(frame); | ||
Serial.println("framebuffer read"); | ||
int i,j,k; | ||
for(i=0, k=0; i<35; i++){ //i is Y pixel pos | ||
for(j=0; j<35; j++, k++){ //j is X pixel pos | ||
//Serial.print(asciiart(frame[k])); | ||
Serial.print(' '); | ||
uint8_t colorIndex = frame[k]; | ||
Serial.print(frame[k]); //print pixel count contained data | ||
//draw the pixels! | ||
tft.fillRect(4+PixelScale * i, 4+PixelScale * j, PixelScale, PixelScale, ironhot[colorIndex]); //Scale up function to fill screen | ||
} | ||
Serial.println(); | ||
} | ||
Serial.println(); | ||
} | ||
|
||
|
||
char asciiart(int k){ //converter magic? Higher value shunts more right in char array | ||
static char foo[] = "WX86*3I>!;~:,`. "; | ||
return foo[k>>4]; //return shunted from array value character | ||
} |
41 changes: 41 additions & 0 deletions
41
examples/PMW3901_Framebuffer_test/PMW3901_Framebuffer_test.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//"THE BEER-WARE LICENSE" (Revision 42): Arsenio Dev wrote this file. As long as you retain this notice you can do whatever you want with this stuff. | ||
//If we meet some day, and you think this stuff is worth it, you can buy me a beer in return. | ||
|
||
#include "Bitcraze_PMW3901.h" | ||
|
||
// Using digital pin 10 for chip select | ||
Bitcraze_PMW3901 flow(10); | ||
char frame[35*35]; //array to hold the framebuffer | ||
|
||
|
||
void setup() { | ||
Serial.begin(115200); | ||
if (!flow.begin()) { | ||
Serial.println("Initialization of the flow sensor failed"); | ||
while(1) { } | ||
} | ||
|
||
flow.enableFrameBuffer(); | ||
Serial.println("framebuffer init"); | ||
} | ||
|
||
|
||
void loop() { | ||
flow.readFrameBuffer(frame); | ||
Serial.println("framebuffer read"); | ||
int i,j,k; | ||
for(i=0, k=0; i<35; i++){ //i is Y pixel pos | ||
for(j=0; j<35; j++, k++){ //j is X pixel pos | ||
Serial.print(asciiart(frame[k])); | ||
Serial.print(' '); | ||
} | ||
Serial.println(); | ||
} | ||
Serial.println(); | ||
} | ||
|
||
|
||
char asciiart(int k){ //converter magic? Higher value shunts more right in char array | ||
static char foo[] = "WX86*3I>!;~:,`. "; | ||
return foo[k>>4]; //return shunted from array value character | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
Bitcraze_PMW3901 KEYWORD1 | ||
readMotionCount KEYWORD2 | ||
enableFrameBuffer KEYWORD2 | ||
readFrameBuffer KEYWORD2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters