Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
sonyPS2_joystick(&PS2, PS2_STICK_RIGHT_X); displayGoto(&LCD,0,1); rprintf("%u",PS2_STICK_RIGHT_X);
#include "hardware.h"#include <stdio.h>#include <math.h>// Initialise the hardwarevoid appInitHardware(void) { initHardware();delay_ms(500);}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {int loop=1;int i=0;//int x; // -------- Start Sony PS2-------// -------- Start Sparkfun serLCD------- //turn on LCD LED_on(&led); delay_ms(500); rprintfInit( displayGetWriter(&LCD)); displayBacklight(&LCD,TRUE); delay_ms(1000); displayGoto(&LCD,0,1); rprintf(" LCD Initialized"); displayGoto(&LCD,0,2); rprintf(" PS2 Ready"); delay_ms(1500); displayClear(&LCD); // -------- End Sparkfun serLCD-------sonyPS2_calibrate(&PS2,27); //-------------main loop---------------------- while(loop==1){ // Read the Sony PS2 and store the result in PS2 if(sonyPS2_read(&PS2)){ // Test if SELECT button pressed if(sonyPS2_buttonPressed(&PS2,PS2_BTN_SELECT)){ // -------- Start Sparkfun serLCD------- //turn on LCD LED_on(&led); delay_ms(500); // Initialise the LCD //displayGoto(&LCD,0,1); rprintfInit( displayGetWriter(&LCD)); displayBacklight(&LCD,TRUE); delay_ms(1000); displayGoto(&LCD,0,1); rprintf(" LCD Initialized"); displayGoto(&LCD,0,2); rprintf(" PS2 Ready"); delay_ms(1500); displayClear(&LCD); } // -------- End Sparkfun serLCD------- //----------PS2 buttons------------------------ if(sonyPS2_buttonPressed(&PS2,PS2_BTN_START)){ LED_off(&led); delay_ms(500); } if(sonyPS2_buttonPressed(&PS2,PS2_BTN_X)){ displayGoto(&LCD,0,0); rprintf("X"); delay_ms(500); displayClear(&LCD); } if(sonyPS2_buttonPressed(&PS2,PS2_BTN_TRIANGLE)){ displayGoto(&LCD,0,0); rprintf("TRIANGLE"); delay_ms(500); displayClear(&LCD); } if(sonyPS2_buttonPressed(&PS2,PS2_BTN_SQUARE)){ displayGoto(&LCD,0,0); rprintf("SQUARE"); delay_ms(500); displayClear(&LCD); } if(sonyPS2_buttonPressed(&PS2,PS2_BTN_CIRCLE)){ displayGoto(&LCD,0,0); rprintf("CIRCLE"); delay_ms(500); displayClear(&LCD); } if(sonyPS2_buttonPressed(&PS2,PS2_BTN_L3)){ displayGoto(&LCD,0,0); rprintf("L3"); delay_ms(500); displayClear(&LCD); } if(sonyPS2_buttonPressed(&PS2,PS2_BTN_L2)){ displayGoto(&LCD,0,0); rprintf("L2"); delay_ms(500); displayClear(&LCD); } if(sonyPS2_buttonPressed(&PS2,PS2_BTN_L1)){ displayGoto(&LCD,0,0); rprintf("L1"); delay_ms(500); displayClear(&LCD); } if(sonyPS2_buttonPressed(&PS2,PS2_BTN_R3)){ displayGoto(&LCD,0,0); rprintf("R3"); delay_ms(500); displayClear(&LCD); } if(sonyPS2_buttonPressed(&PS2,PS2_BTN_R2)){ displayGoto(&LCD,0,0); rprintf("R2"); delay_ms(500); displayClear(&LCD); } if(sonyPS2_buttonPressed(&PS2,PS2_BTN_R1)){ displayGoto(&LCD,0,0); rprintf("R1"); delay_ms(500); displayClear(&LCD); } if(sonyPS2_buttonPressed(&PS2,PS2_DPAD_UP)){ displayGoto(&LCD,0,0); rprintf("UP"); delay_ms(500); displayClear(&LCD); } if(sonyPS2_buttonPressed(&PS2,PS2_DPAD_DOWN)){ displayGoto(&LCD,0,0); rprintf("DOWN"); delay_ms(500); displayClear(&LCD); } if(sonyPS2_buttonPressed(&PS2,PS2_DPAD_RIGHT)){ displayGoto(&LCD,0,0); rprintf("RIGHT"); delay_ms(500); displayClear(&LCD); } if(sonyPS2_buttonPressed(&PS2,PS2_DPAD_LEFT)){ displayGoto(&LCD,0,0); rprintf("LEFT"); delay_ms(500); displayClear(&LCD); } //----------End Button test------------- //----------Start Analog---------sonyPS2_joystick(&PS2, PS2_STICK_RIGHT_X); displayGoto(&LCD,0,1); rprintf("%u",PS2_STICK_RIGHT_X);//int8_t sonyPS2_joystick(const SONY_PS2* controller, PS2_STICK_LEFT_X); if(sonyPS2_isAnalogMode(&PS2)){ displayGoto(&LCD,10,3); rprintf("true"); // delay_ms(500); displayClear(&LCD); } // -------- End Sony PS2-------}} return 0;}
sonyPS2_joystick(&PS2, PS2_STICK_RIGHT_X);
right_stick_x_value = sonyPS2_joystick(&PS2, PS2_STICK_RIGHT_X);displayGoto(&LCD,0,1); rprintf("%u",right_stick_x_value);
int8_t sonyPS2_joystick(const SONY_PS2* controller, PS2_STICK_LEFT_X);
int8_t right_stick_x_value; //declare new variableright_stick_x_value = sonyPS2_joystick(&PS2, PS2_STICK_RIGHT_X); //assign the functions return value to your new variabledisplayGoto(&LCD,0,1); rprintf("%u",right_stick_x_value); // use your variable value here
int8_t right_stick_x_value = sonyPS2_joystick(&PS2, PS2_STICK_RIGHT_X); //declare and assign the functions return value to your new variabledisplayGoto(&LCD,0,1); rprintf("%u",right_stick_x_value); // use your variable value here
displayGoto(&LCD,0,1); rprintf("%u",sonyPS2_joystick(&PS2, PS2_STICK_RIGHT_X)); // use the return value directly here
int8_t is the return type for the function.
void MySubroutine(void) {// do whatever you need}
MySubroutine();
extern void MySubroutine(void);
int MyFunc(void) { // do something return Somevalue;}
MyVal = MyFunc();
Since you are using Webbotlib you should check out the displayHorizGraph() and displayVertGraph() functions in the Displays library as these should do what you want. See the description of the functions here at the bottom of the page.
#include "hardware.h"// Initialise the hardwarevoid appInitHardware(void) { initHardware();}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {int i=1;delay_ms(500);// -------- Start Sparkfun serLCD------- //turn on LCD LED_on(&led);//turn on LCD relay delay_ms(500); rprintfInit( displayGetWriter(&LCD)); //displayBacklight(&LCD,TRUE); displayBacklight(&LCD,FALSE); delay_ms(1000); displayGoto(&LCD,0,1); rprintf(" LCD Initialized"); delay_ms(1000); displayClear(&LCD); // -------- End Sparkfun serLCD-------while(i){//----------------graph start---------------displayHorizGraph(&LCD,0,0,2,19,1);displayVertGraph(&LCD,0,0,2,3,1);//----------------end graph----------------- delay_ms(500); displayClear(&LCD); } return 0;}
displayHorizGraph(&LCD,0,0,2,19,1);displayVertGraph(&LCD,0,0,2,3,1);
// Initialise the hardwarevoid appInitHardware(void) { initHardware(); displayInit();}
displayHorizGraph(&LCD,0,0,17,19,10);displayVertGraph(&LCD,0,0,2,3,10);
#include "hardware.h"// Initialise the hardwarevoid appInitHardware(void) { initHardware();}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {// Initialise the hardwarevoid appInitHardware(void) { initHardware(); displayInit(&LCD);}int i=1;delay_ms(500);// -------- Start Sparkfun serLCD------- //turn on LCD LED_on(&led);//turn on LCD relay delay_ms(500); rprintfInit( displayGetWriter(&LCD)); //displayBacklight(&LCD,TRUE); displayBacklight(&LCD,FALSE); delay_ms(1000); displayGoto(&LCD,0,1); rprintf(" LCD Initialized"); delay_ms(1000); displayClear(&LCD); // -------- End Sparkfun serLCD-------while(i){//----------------graph start---------------displayHorizGraph(&LCD,0,0,17,19,10);displayVertGraph(&LCD,0,0,2,3,10);//----------------end graph----------------- delay_ms(500); displayClear(&LCD); } return 0;}
#include "hardware.h"// Initialise the hardwarevoid appInitHardware(void) {// Place code you use to initialise hardware here initHardware(); //add the LCD hardware initialisation to this section displayInit(&LCD); rprintfInit( displayGetWriter(&LCD));}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){// Place code you only need to run once here // -------- Start Sparkfun serLCD------- //turn on LCD LED_on(&led); //turn on LCD relay delay_ms(500); //displayBacklight(&LCD,TRUE); displayBacklight(&LCD,FALSE); displayGoto(&LCD,0,1); rprintf(" LCD Initialized"); delay_ms(1000); displayClear(&LCD); // -------- End Sparkfun serLCD------- return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {// put your looping code here //Draw Graph displayHorizGraph(&LCD, 1, 1, 50, 100, 18); delay_ms(2000); displayClear(&LCD); return 0;}
it honestly wouldn't surprise me if there is an issue with this LCD because it has a history of being a problem child
the graphing functions then it may be a Webbotlib bug in the Sparkfun display library graph routines... or more likely just something I have overlooked
#include "hardware.h"// Initialise the hardwarevoid appInitHardware(void) { initHardware();}int cols;// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){ displayAutoScroll(&display,FALSE); displayLineWrap(&display,FALSE); cols = MIN(NUM_ADC_CHANNELS, displayColumns(&display)); for(int n=0; n<cols;n++){ rprintf("%d",n % 10); } return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { int depth = displayLines(&display)-1; for(int ch = 0; ch<cols; ch++){ uint8_t val = a2dConvert8bit(ADC_NUMBER_TO_CHANNEL(ch)); displayVertGraph(&display,ch,1, val, 255, depth); } return 0;}
#include "hardware.h"// Initialise the hardwarevoid appInitHardware(void) { initHardware();delay_ms(1000);//----LCD power relay output--------------pin_make_output(G5,FALSE);pin_high(G5);//turn relay on//----------------------------------------delay_ms(1000);//---Initialize LCD/enable rprintf--------displayInit(&display); rprintfInit( displayGetWriter(&display));//----------------------------------------}int cols;// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){ displayAutoScroll(&display,FALSE); displayLineWrap(&display,FALSE); cols = MIN(NUM_ADC_CHANNELS, displayColumns(&display)); for(int n=0; n<cols;n++){ rprintf("%d",n % 10); } delay_ms(1000); return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { int depth = displayLines(&display)-1; for(int ch = 0; ch<cols; ch++){ uint8_t val = a2dConvert8bit(ADC_NUMBER_TO_CHANNEL(ch)); displayVertGraph(&display,ch,1, val, 255, depth);//----------print IR values (DEBUG)-----------------if(ch==0){ displayGoto(&display,0,3); rprintf("1:%d",val); }if(ch==1){ displayGoto(&display,6,3); rprintf("2:%d",val); }if(ch==2){ displayGoto(&display,12,3); rprintf("3:%d",val); }//-------------end print(DEBUG)--------------------------- }delay_ms(100); return 0;}
#include "hardware.h"// Initialise the hardwarevoid appInitHardware(void) { initHardware();delay_ms(1000);//----LCD power relay output--------------pin_make_output(G5,FALSE);pin_high(G5);//turn relay on//----------------------------------------delay_ms(1000);}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){ displayAutoScroll(&display,FALSE); displayLineWrap(&display,FALSE);delay_ms(1000); return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { displayVertGraph(&display,1,1, 128, 255, 1);delay_ms(100); return 0;}
You are using the Sparkfun serLCD right?
The 'Sparkfun serLCD' doesn't support the horiz/vertGraph function
And they still don't support the use of programmable characters! Doh !
the fix works webbot and will suffice for what i wanted to do. If possible, this should be in webbotlib 1.30
do you have any recommendations for my next LCD screen?
Matrix Orbital serial displays
steering=sonyPS2_joystick(&PS2, PS2_STICK_LEFT_X);//grab ps2 joy stick valuethrottle=sonyPS2_joystick(&PS2, PS2_STICK_LEFT_Y);//grab ps2 joy stick value//-----------scaling code----------------if(steering<0){steering=(steering*(100*motors_min/left_joy_x_min))/100;} if(steering>0){steering=(steering*(100*motors_max/left_joy_x_max))/100; } if(throttle<0){throttle=(throttle*(100*motors_min/left_joy_y_min))/100;} if(throttle>0){throttle=(throttle*(100*motors_max/left_joy_y_max))/100;}//----------auto scaling end--------------------//------------speed calculater-------------velocity=sqrt(throttle*throttle+steering*steering);if(velocity>=99){velocity=99;}if(throttle<0){velocity=-velocity;}//------------end speed-----------------//=======================================================================================//------------analog tank mixing-----------------if(steering>0&&throttle<0){//sector1act_setSpeed(&motor1,velocity+steering*2);act_setSpeed(&motor2,velocity);delay_ms(5);}else if(steering<0&&throttle<0){//sector2act_setSpeed(&motor1,velocity);act_setSpeed(&motor2,velocity-steering*2);delay_ms(5);}else if(steering<0&&throttle>0){//sector3act_setSpeed(&motor1,velocity+steering*2);act_setSpeed(&motor2,velocity);delay_ms(5);}else if(steering>0&&throttle>0){//sector4act_setSpeed(&motor1,velocity);act_setSpeed(&motor2,velocity-steering*2);delay_ms(5);}else if(steering>0&&throttle==0){//left power spinact_setSpeed(&motor1,velocity);act_setSpeed(&motor2,-velocity);delay_ms(5);}else if(steering<0&&throttle==0){//right power spinact_setSpeed(&motor1,-velocity);act_setSpeed(&motor2,velocity);delay_ms(5);}else{//fowards/backwards/stopact_setSpeed(&motor1,velocity);act_setSpeed(&motor2,velocity);delay_ms(5);}//---------------exit mixer-----------------
Mathematically it will return:minRtn+((value-minVal)*(maxRtn-minRtn)/(maxVal-minVal))