Error 841 with an OLED screen
/*It 's in javascript*/
function degtorad (num: number) {
return num * Math.PI / 180
}
function draw_line (x1: number, y1: number, x2: number, y2: number, color: number) {
dx = x2 - x1
dy = y2 - y1
for(let x = x1;x < x2; x++){
let y = y1 + dy * (x- x1) / dx
OLED12864_I2C.pixel(x, y, color)
}
}
function coo (angle: number, dist: number) {
radangle = degtorad(angle)
x2 = Math.cos(radangle) * (dist * (64 / 400))
y2 = Math.sin(radangle) * (dist * (64 / 400))
return [x2 + 64, y2 + 62]
}
let arr: number[] = []
let dist = 0
let i = 0
let y2 = 0
let radangle = 0
let dx = 0
let dy = 0
let x2 = 0
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
OLED12864_I2C.init(60)
OLED12864_I2C.on()
OLED12864_I2C.clear()
let minborne = 25
let maxborne = 65
basic.forever(function () {
if (1 == pins.digitalReadPin(DigitalPin.P1)) {
pins.analogWritePin(AnalogPin.P0, 488)
}
if (1 == pins.digitalReadPin(DigitalPin.P2)) {
pins.analogWritePin(AnalogPin.P0, 0)
}
robotbit.GeekServo5KG(robotbit.Servos.S1, i)
dist = sonar.ping(
DigitalPin.P15,
DigitalPin.P14,
PingUnit.Centimeters
)
arr = coo(i, 400)/* it work without this*/
draw_line(64, 62, arr[0], arr[1], 0)/*this*/
arr = coo(i, dist)/*this*/
draw_line(64, 62, arr[0], arr[1], 1)/* and this*/
if (i == maxborne) {
i = minborne
}
i += 1
})
Expected behaviour It erases the line with max length, and it draws the line with the distance the sonar calculate
Code with extension on GitHub https://github.com/Masterkiller25/radar
DETAILS.TXT
# DAPLink Firmware - see https://mbed.com/daplink
Unique ID: 9901000051114e4500657006000000550000000097969901
HIC ID: 97969901
Auto Reset: 1
Automation allowed: 0
Overflow detection: 0
Daplink Mode: Interface
Interface Version: 0253
Bootloader Version: 0243
Git SHA: 64359f5c786363065a41ec15c348e3d53568da03
Local Mods: 0
USB Interfaces: MSD, CDC, HID, WebUSB
Bootloader CRC: 0x32eb3cfd
Interface CRC: 0x53375800
Remount count: 0
URL: https://microbit.org/device/?id=9901&v=0253
Desktop :
- OS: Windows
- Browser chrome
- Version 22H2
Additional context I use an OLED screen with i²c, and I test it with show numbers and it's work The error code appearer after 7 sec, and it rests 11 sec then the micro:bit is rebooting
@Masterkiller25 Please post a hex file, or shared project URL.
Additional information not given.
@Masterkiller25 I have looked at another example with the OLED12864 extension
Ensure all pixel coordinates in your draw_line function are within the screen.
Coordinates outside the screen make the extension calculate an index that is beyond the end of its _screen byte buffer. https://github.com/makecode-extensions/OLED12864_I2C/blob/127c10de32c07df9d274b4ba3594ffef4c2785e1/OLED12864_I2C.ts#L192