2021-01-17 07:41:25 +00:00
# include <string.h>
# include <math.h>
# include <vector>
# include <cstdlib>
# include "pico_explorer.hpp"
2021-01-17 16:05:28 +00:00
# include "msa301.hpp"
2021-01-17 07:41:25 +00:00
using namespace pimoroni ;
2021-01-17 16:59:58 +00:00
extern unsigned char _binary_fox_tga_start [ ] ;
2021-01-17 07:41:25 +00:00
2021-01-21 00:52:33 +00:00
uint16_t buffer [ PicoExplorer : : WIDTH * PicoExplorer : : HEIGHT ] ;
PicoExplorer pico_explorer ( buffer ) ;
2021-01-17 16:05:28 +00:00
MSA301 msa301 ;
2021-01-17 07:41:25 +00:00
uint8_t arrow [ ] = {
0b00010000 ,
0b00110000 ,
0b01110000 ,
0b11111111 ,
0b11111111 ,
0b01110000 ,
0b00110000 ,
0b00010000
} ;
uint8_t tick [ ] = {
0b00000000 ,
0b00000010 ,
0b00000111 ,
0b01001110 ,
0b11111100 ,
0b00111000 ,
0b00010000 ,
0b00000000 ,
} ;
/*
void sprite ( uint8_t * p , int x , int y , bool flip , uint16_t c ) {
for ( int ay = 0 ; ay < 8 ; ay + + ) {
uint8_t sl = p [ ay ] ;
for ( int ax = 0 ; ax < 8 ; ax + + ) {
if ( flip ) {
if ( ( 0b10000000 > > ax ) & sl ) {
pixel ( ax + x , ay + y , c ) ;
}
} else {
if ( ( 0b1 < < ax ) & sl ) {
pixel ( ax + x , ay + y , c ) ;
}
}
}
}
} */
int main ( ) {
2021-01-21 00:52:33 +00:00
pico_explorer . init ( ) ;
2021-01-17 16:05:28 +00:00
msa301 . init ( ) ;
2021-01-17 07:41:25 +00:00
struct pt {
float x ;
float y ;
uint8_t r ;
float dx ;
float dy ;
uint16_t pen ;
} ;
std : : vector < pt > shapes ;
for ( int i = 0 ; i < 100 ; i + + ) {
pt shape ;
shape . x = rand ( ) % 240 ;
shape . y = rand ( ) % 135 ;
shape . r = ( rand ( ) % 10 ) + 3 ;
shape . dx = float ( rand ( ) % 255 ) / 128.0f ;
shape . dy = float ( rand ( ) % 255 ) / 128.0f ;
shape . pen = pico_explorer . create_pen ( rand ( ) % 255 , rand ( ) % 255 , rand ( ) % 255 ) ;
shapes . push_back ( shape ) ;
}
2021-01-17 09:18:58 +00:00
pico_explorer . set_audio_pin ( pico_explorer . GP0 ) ;
2021-01-19 07:10:26 +00:00
2021-01-17 07:41:25 +00:00
uint32_t i = 0 ;
while ( true ) {
pico_explorer . set_pen ( 120 , 40 , 60 ) ;
2021-01-18 07:58:19 +00:00
pico_explorer . clear ( ) ;
2021-01-17 07:41:25 +00:00
for ( auto & shape : shapes ) {
shape . x + = shape . dx ;
shape . y + = shape . dy ;
if ( shape . x < 0 ) shape . dx * = - 1 ;
2021-01-18 07:58:19 +00:00
if ( shape . x > = pico_explorer . bounds . w ) shape . dx * = - 1 ;
2021-01-17 07:41:25 +00:00
if ( shape . y < 0 ) shape . dy * = - 1 ;
2021-01-18 07:58:19 +00:00
if ( shape . y > = pico_explorer . bounds . h ) shape . dy * = - 1 ;
2021-01-17 07:41:25 +00:00
pico_explorer . set_pen ( shape . pen ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . circle ( Point ( shape . x , shape . y ) , shape . r ) ;
2021-01-17 07:41:25 +00:00
}
2021-01-17 09:18:58 +00:00
float rv = pico_explorer . get_adc ( pico_explorer . ADC0 ) ;
pico_explorer . set_pen ( 255 , 255 , 255 ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . circle ( Point ( rv * 140 + 50 , 110 ) , 20 ) ;
2021-01-17 09:18:58 +00:00
pico_explorer . set_pen ( rv * 255 , 0 , 0 ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . circle ( Point ( rv * 140 + 50 , 110 ) , 15 ) ;
2021-01-17 09:18:58 +00:00
float gv = pico_explorer . get_adc ( pico_explorer . ADC1 ) ;
pico_explorer . set_pen ( 255 , 255 , 255 ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . circle ( Point ( gv * 140 + 50 , 160 ) , 20 ) ;
2021-01-17 09:18:58 +00:00
pico_explorer . set_pen ( 0 , gv * 255 , 0 ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . circle ( Point ( gv * 140 + 50 , 160 ) , 15 ) ;
2021-01-17 09:18:58 +00:00
float bv = pico_explorer . get_adc ( pico_explorer . ADC2 ) ;
pico_explorer . set_pen ( 255 , 255 , 255 ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . circle ( Point ( bv * 140 + 50 , 210 ) , 20 ) ;
2021-01-17 09:18:58 +00:00
pico_explorer . set_pen ( 0 , 0 , bv * 255 ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . circle ( Point ( bv * 140 + 50 , 210 ) , 15 ) ;
2021-01-17 09:18:58 +00:00
pico_explorer . set_motor ( pico_explorer . MOTOR1 , pico_explorer . FORWARD , bv ) ;
2021-01-17 16:05:28 +00:00
pico_explorer . set_motor ( pico_explorer . MOTOR2 , pico_explorer . FORWARD , rv ) ;
2021-01-17 09:18:58 +00:00
2021-01-19 07:10:26 +00:00
pico_explorer . set_tone ( 440 , 0.5 ) ;
if ( pico_explorer . is_pressed ( pico_explorer . A ) ) {
pico_explorer . set_pen ( 255 , 255 , 255 ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . character ( ' A ' , Point ( 120 , 180 ) , 5 ) ;
2021-01-19 07:10:26 +00:00
}
if ( pico_explorer . is_pressed ( pico_explorer . B ) ) {
pico_explorer . set_pen ( 255 , 255 , 255 ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . character ( ' B ' , Point ( 120 , 180 ) , 5 ) ;
2021-01-19 07:10:26 +00:00
}
if ( pico_explorer . is_pressed ( pico_explorer . X ) ) {
pico_explorer . set_pen ( 255 , 255 , 255 ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . character ( ' X ' , Point ( 120 , 180 ) , 5 ) ;
2021-01-19 07:10:26 +00:00
}
if ( pico_explorer . is_pressed ( pico_explorer . Y ) ) {
pico_explorer . set_pen ( 255 , 255 , 255 ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . character ( ' Y ' , Point ( 120 , 180 ) , 5 ) ;
2021-01-19 07:10:26 +00:00
}
2021-01-17 16:05:28 +00:00
2021-01-18 07:58:19 +00:00
float tyoff = cos ( i / 20.0f ) * 50.0f - 50.0f ;
2021-01-23 23:41:09 +00:00
Rect text_box ( 10 , 10 , 150 , 150 ) ;
2021-01-18 07:58:19 +00:00
pico_explorer . set_pen ( 55 , 65 , 75 ) ;
pico_explorer . rectangle ( text_box ) ;
text_box . deflate ( 10 ) ;
pico_explorer . set_clip ( text_box ) ;
2021-01-17 16:05:28 +00:00
pico_explorer . set_pen ( 255 , 255 , 255 ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . text ( " This is a test of some text data that should wrap nicely onto multiple lines which is dead useful like. " , Point ( text_box . x , text_box . y + tyoff ) , 100 ) ;
2021-01-17 16:05:28 +00:00
float xoff = sin ( i / 20.0f ) * 50.0f ;
xoff + = 120 - ( 81 / 2 ) ;
float yoff = cos ( i / 20.0f ) * 50.0f ;
yoff + = 120 - ( 68 / 2 ) ;
for ( int y = 0 ; y < 68 ; y + + ) {
2021-05-17 16:20:42 +01:00
// uint16_t *dest = pico_explorer.frame_buffer + (y * 240);
2021-01-17 16:59:58 +00:00
uint8_t * src = _binary_fox_tga_start + 18 + ( y * 81 * 3 ) ;
2021-01-17 16:05:28 +00:00
for ( int x = 0 ; x < 81 ; x + + ) {
uint8_t b = * src + + ;
2021-02-23 15:15:01 +00:00
uint8_t g = * src + + ;
uint8_t r = * src + + ;
2021-01-17 16:05:28 +00:00
pico_explorer . set_pen ( r , g , b ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . pixel ( Point ( x + xoff , 68 - y + yoff ) ) ;
2021-01-17 16:05:28 +00:00
}
}
2021-01-18 07:58:19 +00:00
pico_explorer . remove_clip ( ) ;
pico_explorer . set_pen ( 255 , 255 , 255 ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . text ( " x: " + std : : to_string ( int ( msa301 . get_axis ( msa301 . X , 16 ) * 100 ) ) , Point ( 10 , 190 ) , 100 ) ;
pico_explorer . text ( " y: " + std : : to_string ( int ( msa301 . get_axis ( msa301 . Y , 16 ) * 100 ) ) , Point ( 10 , 205 ) , 100 ) ;
pico_explorer . text ( " z: " + std : : to_string ( int ( msa301 . get_axis ( msa301 . Z , 16 ) * 100 ) ) , Point ( 10 , 220 ) , 100 ) ;
2021-01-18 07:58:19 +00:00
uint16_t xpos = ( msa301 . get_axis ( msa301 . X , 16 ) * 120 ) + 120 ;
uint16_t ypos = ( msa301 . get_axis ( msa301 . Z , 16 ) * 120 ) + 120 ;
pico_explorer . set_pen ( 255 , 255 , 255 ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . circle ( Point ( xpos , ypos ) , 20 ) ;
2021-01-18 07:58:19 +00:00
pico_explorer . set_pen ( 255 , 0 , 255 ) ;
2021-01-23 23:41:09 +00:00
pico_explorer . circle ( Point ( xpos , ypos ) , 15 ) ;
2021-01-18 07:58:19 +00:00
2021-01-17 07:41:25 +00:00
/*
if ( pico_display . is_pressed ( pico_display . A ) ) {
pico_display . rectangle ( 0 , 0 , 18 , 18 ) ;
//sprite(tick, 5, 5, true, green);
} else {
//sprite(arrow, 10 + bounce, 10, true, white);
}
if ( pico_display . is_pressed ( pico_display . B ) ) {
pico_display . rectangle ( 0 , 49 , 18 , 18 ) ;
//sprite(tick, 5, 54, true, green);
} else {
//sprite(arrow, 10 - bounce, 50, true, white);
}
if ( pico_display . is_pressed ( pico_display . X ) ) {
pico_display . rectangle ( 102 , 0 , 18 , 18 ) ;
//sprite(tick, 107, 5, true, green);
} else {
//sprite(arrow, 102 - bounce, 10, false, white);
}
if ( pico_display . is_pressed ( pico_display . Y ) ) {
pico_display . rectangle ( 102 , 49 , 18 , 18 ) ;
//sprite(tick, 107, 54, true, green);
} else {
//sprite(arrow, 102 + bounce, 50, false, white);
}
*/
// update screen
pico_explorer . update ( ) ;
i + + ;
}
return 0 ;
}