Forum Request: Scrolling codebox, please
Phil Pilgrim (PhiPi)
Posts: 23,514
As long as the [noparse]
Thanks,
-Phil
[/noparse] thing is being worked on, can we have scrolling code boxes like we did before, please? [code]CON SINE = $e000 OBJ u : "umath" PUB distance_m(lat0, long0, lat1, long1) | dx, dy dy := lat1 - lat0 dx := (long1 - long0) * cos(lat0 / 100_000) / 10_000 return u.multdiv(^^(dx * dx + dy * dy), 111_319, 1_000_000) PUB distance_mm(lat0, long0, lat1, long1) | dx, dy dy := lat1 - lat0 dx := (long1 - long0) * cos(lat0 / 100_000) / 10_000 return u.multdiv(^^(dx * dx + dy * dy), 111_319, 1_000) PUB distance_cm(lat0, long0, lat1, long1) | dx, dy dy := lat1 - lat0 dx := (long1 - long0) * cos(lat0 / 100_000) / 10_000 return u.multdiv(^^(dx * dx + dy * dy), 111_319, 10_000) PUB bearing(lat0, long0, lat1, long1) | dx, dy dy := lat1 - lat0 dx := (long1 - long0) * cos(lat0 / 100_000) / 10_000 result := 900 - atan2(dy, dx) repeat while result < 0 result += 3600 result //= 3600 PUB degminsec2deg(degrees, minutes, second_hundredths) 'Arguments are in whole degrees, whole minutes, and whole seconds. 'Return value is in degrees * 1_000_000. return degrees * 1_000_000 + minutes * 100_000 / 6 + second_hundredths * 100 / 36 PUB degmin2deg (degrees, minute_hundred_thousandths) 'Arguments are whole degrees, minutes * 100_000. 'Return value is in degrees * 1_000_000. return degrees * 1_000_000 + minute_hundred_thousandths / 6 PUB cos(x) 'Argument x is in tenths of a degree. return sin(x + 900) PUB sin(x) : value 'Argument x is in tenths of a degree. x := x * $2000 / 3600 if (x & $fff == $800) value := $1_0000 elseif (x & $800) value := word[SINE][-x & $7ff] else value := word[SINE][x & $7ff] if (x & $1000) value := -value value := (value * 10_000) ~> 16 PUB atan2(y, x) : a | negate, i, da, dx, dy 'CORDIC atan2 algorithm ' ' - angle range: -1800 to 1799 tenths of a degree. ' - hypotenuse of x,y must be within ±1_300_000_000 to avoid overflow i := 29 - >|(||x #> ||y) 'Make the arguments as large as possible. if (i > 0) x <<= i y <<= i a~ negate := x < 0 'check quadrant 2 | 3 if negate 'if quadrant 2 | 3, (may be outside ±106° convergence range) a += $80000000 '..add 180 degrees to angle -x '..negate x -y '..negate y repeat i from 0 to 26 'do CORDIC iterations (27 is optimal for 32-bit values) da := corlut[i] dx := y ~> i dy := x ~> i negate := y < 0 'if atan2 mode, drive y towards 0 if negate -da -dx -dy a += da x += dx y -= dy a := (((a ~> 16) * 3600) ~> 16) 'Convert to tenths of a degree. PUB error_angle(angle) result := angle repeat while (result > 1800) result -= 3600 repeat while (result < -1800) result += 3600 PUB compass_angle(angle) result := angle repeat while result > 3600 result -= 3600 repeat while result < 0 result += 3600 DAT corlut long $20000000 'CORDIC angle lookup table long $12E4051E long $09FB385B long $051111D4 long $028B0D43 long $0145D7E1 long $00A2F61E long $00517C55 long $0028BE53 long $00145F2F long $000A2F98 long $000517CC long $00028BE6 long $000145F3 long $0000A2FA long $0000517D long $000028BE long $0000145F long $00000A30 long $00000518 long $0000028C long $00000146 long $000000A3 long $00000051 long $00000029 long $00000014 long $0000000A
Thanks,
-Phil
Comments
So I took it out, and it still works...
-Phil
CODE: [SELECT ALL] [EXPAND/COLLAPSE] [DOWNLOAD]
with a File name and a language selector for the code highlighter.
Surprising Parallax have code support so far down their list.
-Phil
It looks like the code text is just a bit larger than the normal forum text. It's not a big deal but I wonder if anyone else thinks the text looks kind of large?
Thanks for posting this example. I'm adding the HTML to my bag of forum tricks (most of the other tricks I learned from Heater ("tricks" is a nicer name than some of his "formatting techniques" deserve)).
Agreed - on 2 browsers here (Firefox,Chrome) it is larger than needs to be, and also the line-line spacing is a little larger too.
Background colour differs slightly in the 2 browsers.
-Phil
It renders as a 'somewhat large' 11pts - less line spacing is probably a good idea, - put in some of the tallest chars in a comment and try it ?
Can you do another window, (maybe in a post below this one) with simple courier font to see how that scales ? Prop font support is nice to have, but not all code needs it.
I'm not sure if it's a good idea to try to replicate the look of the Prop Tool or not but it would be nice if schematics in the code would show up in the forum.
Again, it looks good as it is so it's not a big deal IMO if you don't change it at all.
Here trying your template. Want to see how it comes out with some of the Parallax schematic drawing characters.
[code]
'' EXAMPLE 1.?? : Light meter, LED both measure light and indicates brightness
''
'' DIFFICULTY LEVEL: Very easy
''
'' Submitted by Tracy Allen, 1 March 2006
'' File: Example01_lightMeter1.spin
''
''PURPOSE:
'' -- This program shows how an LED can be used to measure light by using in in reverse bias
'' mode as a photodiode. The current produced by light discharges a capacitor. and a
'' propeller input pin detects when the voltage level passes through the ~1.5 volt input
'' threshold. The time required to discharge the capacitor changes with light level,
'' and that changes the rate at which the program repeats its main loop.
'' Each time through the loop, the program turns the LED to its normal use and has it emit a
'' brief flash of light. This indicates how fast the program loop is running, and
'' therefore the light level.
'' -- This example illustrates the electronics of the LED as both an input and an output device,
'' and how to wire up a simple circuit on the prototyping block.
'' -- This program shows how to set a Propeller pin for input and how to make it wait
'' while the input is high, until the capacitor discharges, and the voltage at the
'' hits the propeller input threshold of ~1.5 volts, and the input suddenly reads as
'' zero. The program shows how to do that using a coded repeat loop with the "until"
'' modifier, and alternatively how to use the unique propeller commands waitpeq and waitpne
'' to accomplish the same thing. The program uses only one COG.
'' -- Parts required, one green LED, one 330 ohm resistor, one 220pf capacitor, one jumper wire.
'' These parts must be mounted on the white prototyping block with connection to the
'' Propeller pins.
'' The LED is connected between two input pins, with the anode to pin LEDp=1 and the cathode
'' to pin LEDn=0. It uses two pins so it can use the LED in normal forward mode to blink it,
'' and reverse bias as a photodiode. Note that the longer leg of an LED is usually the anode.
''
'' -- The following is the circuit diagram rendered in ascii...
''
'' 330 green LED
'' a1?
//---o--->|
, a1 (+)
>|
(-) a0
'' | p n |
> forward bias
'' | | lights LED
'' === 220pf |
'' | |
'' a0?
o
' a1 (-)
>|
(+) a0
''
I do prefer simple ASCII Schematics. No questions of 'how portable'.
Even the ASCII version above, seems to have a couple of Non ASCII chars after a0.a1?
This is what I'm using now for the <pre> tag:
<pre style="background-color:#ffffe0;max-height:400px;max-width:fill-available;overflow:auto;font-family:Parallax,Courier,monospaced;font-size:11pt;line-height:11pt;border-style:solid;border-width:1px;padding:5px">
I changed the line-height style here and in the first post to 11pt to match the font-size.
Tracy, I didn't do anything special to get a complete listing. It's odd that yours got cut off.
-Phil
I changed the line-height style here and in the first post to 11pt to match the font-size.
Looks here like that is an improvement.
"most of the other tricks I learned from Heater ("tricks" is a nicer name than some of his "formatting techniques" deserve)"
But Duane, I don't have any "tricks". Nothing underhand or up my sleeve. Just straight, vanilla (get it?) HTML. The same HTML we are invited to use by being given a WYSIWYG HTML text editor box to post in to.
By the way there is an excellent user manual for using this input box here: http://www.w3schools.com
Code boxes should again be scrollable once it is in place.
Code boxes should again be scrollable once it is in place.
Thanks!
*****************************************
* Servo32v9 Driver v9 *
* Author: Beau Schwabe *
* Copyright (c) 2013 Parallax *
* See end of file for terms of use. *
*****************************************
*****************************************************************
Control up to 32-Servos Version 9 04-05-2013
*****************************************************************
Coded by Beau Schwabe (Parallax).
*****************************************************************
History:
Version 1 - initial concept
Version 2 - (03-08-2006) Beta release
Version 3 - (11-04-2007) Improved servo resolution to 1uS
Version 4 - (05-03-2009) Ability to disable a servo channel
and remove channel preset requirement
Version 5 - (05-08-2009) Added ramping ability
Version 6 - (07-18-2009) Fixed slight timing skew in ZoneLoop and
fixed overhead timing latency in ZoneCore
Version 7 - (08-18-2009) Fixed servo jitter in ramping function when
servo reached it's target position
Version 8 - (12-20-2010) Added PUB method to retrieve servo position
Version 9 - (04-05-2013) cnt rollover issue corrected with ZonePeriod
by setting up Counter A and using the Phase
accumulator instead of the cnt
Note: This also eliminates the need to setup
a 'NoGlitch' variable
Theory of Operation:
Each servo requires a pulse that varies from 1mS to 2mS with a period of 20mS.
To prevent a current surge nightmare, I have broken the 20mS period into four
groups or Zones of 8 servos each with a period of 5mS. What this does, is to
ensure that at any given moment in time, a maximum of only 8 servos are receiving
a pulse.
Zone1 Zone2 Zone3 Zone4 In Zone1, servo pins 0- 7 are active
???????????????????????????? In Zone2, servo pins 8-15 are active
???5mS????5mS????5mS????5mS?? In Zone3, servo pins 16-23 are active
????????????20mS????????????? In Zone4, servo pins 24-31 are active
?? ?? ?? ??
?? 1-2mS servo pulse ??
The preferred circuit of choice is to place a 4.7K resistor on each signal input
to the servo. If long leads are used, place a 1000uF cap at the servo power
connector. Servo's seem to be happy with a 5V supply receiving a 3.3V signal.
}}
CON
_1uS = 1_000_000 / 1 'Divisor for 1 uS
ZonePeriod = 5_000 '5mS (1/4th of typical servo period of 20mS)
LowRange = 500 ' Width Pin Width Pin