This project was used to test the MAP or scale function in Contributors.
I map readad to pulseout range for a servo actuator.
I then map pulseout to degrees and display as a dial.
It's a pretty servo actuator tester. poor video. https://www.youtube.com/watch?v=riaFvlKl1kE&feature=youtu.be
;scalepotentiometerreadadto45-315degforglcdand;scaleto.75to2.25msforsevoactuator#chipmega328p,16#include<UNO_mega328p.h>#optionexplicit#include<glcd.h>#INCLUDE<TRIG2PLACES.H>;#defineAD_REF_SOURCEAD_REF_256#defineADSpeedlowSpeed;----glcdsetup#defineGLCD_TYPEGLCD_TYPE_ILI9341'Pin mappings for SPI - this GLCD driver supports Hardware SPI and Software SPI#define GLCD_DC DIGITAL_8 'Datacommandline#defineGLCD_CSDIGITAL_10' Chip select line#define GLCD_RESET DIGITAL_9 'Resetline,youcouldjusttiehigh#defineGLCD_DIDIGITAL_12' Data in | MISO - Not used therefore not really required#define GLCD_DO DIGITAL_11 'Dataout|MOSI#defineGLCD_SCKDIGITAL_13' Clock Line;#define ILI9341_HardwareSPI 'remove/commentoutifyouwanttousesoftwareSPI.#defineGLCD_EXTENDEDFONTSET1GLCDfntDefaultsize=2GLCDCLSili9341_blackGLCDBackground=ili9341_blueGLCDRotate(3);----glcddone,startprogramdimradius,xcentre,ycentre,xstart,ystart,xend,yend,pulse_outasbytedimangle,needlecolour,newval,oldvalasworddirportc.0in;readadpindirportd.7out;toservo;radius=170xcentre=160ycentre=120oldval=180;centrenewval=180;ofgauge;;----drawthegaugefilledcircle(xcentre,ycentre,79,ili9341_blue)circle(xcentre,ycentre,80,ili9341_white)filledcircle(xcentre,ycentre,9,ili9341_red)circle(xcentre,ycentre,10,ili9341_white)filledBox104,180,216,200,ili9341_black;ruboutcirclebaseline108,179,212,179,ili9341_whiteneedlecolour=ili9341_yellowdraw_needle;----startofmainprogramDopulse_out=scale(ReadAD(portc.0),0,255,75,225);scalereadadtopulse_outGLCDprint140,154,str(pulse_out)+" ",ili9341_whitenewval=Scale(pulse_out,75,225,45,314);scalepulse_outtogaugeifnewval<>oldvalthenerase_needledraw_needleoldval=newvalendifpulseoutportd.7,pulse_out10us;outtoservowait5ms;bestaddthiscosit's so fastLoop;end of main program..that'sitEnd;Anobiumsscalefromto..lookscomplicateded...stylefunctionscale(inl_mapasword,inl_fromLowasinteger,inl_fromHighasinteger,inl_toLowasinteger,inl_toHighasinteger)asintegerdiml_syscalcasintegerdiml_syscalcFaslongl_syscalcf=0repeat(l_toHigh-l_toLow)l_syscalcf=l_syscalcf+(l_map-l_fromLow)endRepeatl_syscalc=(l_fromHigh-l_fromLow)scale=(l_syscalcf/l_syscalc)+l_toLowendfunction;suberase_needleangle=oldvalneedlecolour=ILI9341_blueneedle;eraseneedleendsub;subdraw_needleangle=newvalneedlecolour=ILI9341_yellowneedle;drawneedleendsub;subneedle;drawsneedleinneedlecolourxstart=xcentre-30*sin(angle)/255ystart=ycentre+30*cos(angle)/255xend=xstart-radius*sin(angle)/255yend=ystart+radius*cos(angle)/255line(xstart,ystart,xend,yend,needlecolour)endsub
Last edit: stan cartwright 2018-02-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Have we resolved the ADC read issue? How did you resolve?
I will move Scale to the distribution soon - once I have resolved a little issue I have. The final Scale code may look simplier but if it does not perform faster then the existing code - I will retain the existing method. Speed is of the essence in this conversion.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Resolved considering the 5V pin is not 5V but 4.67 on a dvm.
How did I get by without "Scale"...sums for each time, ha!
Whatever it's final name, it's a useful function.
The display and pulseout was so easy..no brain needed.
There is a slight error in my prog that 150 10 us should be vertical line mid display but it's not quite. maybe scaling twice instead of both scales from ad.
just demoing gcb. well impressed with math handling speed.
glcd graphics are very good to.
It's a couldn't do that with picaxe program. :(
ps the idea was the servo follows the display but different servos have different range
Last edit: stan cartwright 2018-02-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This project was used to test the MAP or scale function in Contributors.
I map readad to pulseout range for a servo actuator.
I then map pulseout to degrees and display as a dial.
It's a pretty servo actuator tester. poor video. https://www.youtube.com/watch?v=riaFvlKl1kE&feature=youtu.be
Last edit: stan cartwright 2018-02-21
Nice.
Have we resolved the ADC read issue? How did you resolve?
I will move Scale to the distribution soon - once I have resolved a little issue I have. The final Scale code may look simplier but if it does not perform faster then the existing code - I will retain the existing method. Speed is of the essence in this conversion.
Resolved considering the 5V pin is not 5V but 4.67 on a dvm.
How did I get by without "Scale"...sums for each time, ha!
Whatever it's final name, it's a useful function.
The display and pulseout was so easy..no brain needed.
There is a slight error in my prog that 150 10 us should be vertical line mid display but it's not quite. maybe scaling twice instead of both scales from ad.
just demoing gcb. well impressed with math handling speed.
glcd graphics are very good to.
It's a couldn't do that with picaxe program. :(
ps the idea was the servo follows the display but different servos have different range
Last edit: stan cartwright 2018-02-21
This is the final code that i will include in the next release.
It is 3 times faster and now includes an optional calibrate parameter to enable a calibration offset to be applied.
Enjoj]y
Last edit: Anobium 2018-02-28
Not tested yet. Nice one.