Close

Thumbs Up Bitmap Demo

A project log for HariFun#134 Oscilloscope Abuse

Arduino byte-banging text and bitmap onto an oscilloscope

Hari WigunaHari Wiguna 05/01/2016 at 08:020 Comments
// Drawing a bitmap on scope by Hari Wiguna, 2016
// Playing with R-2R Ladder to convert Digital to Analog
// We'll use PORTD because it gives us contiguous 8 bits
// Thanks to digole.com for the bitmap to array converter: http://www.digole.com/tools/PicturetoC_Hex_converter.php

const uint8_t xMax = 219; // # of columns
const uint8_t yMax = 230; // # of rows
const uint8_t bandMax = 28;  // 219/8 rounded up
// This is only some of the bytes of the bitmap.
// See github for full listing.

const unsigned char image[] PROGMEM = {

0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f }; void setup() { DDRD = B11111111; // Set all bits of PORTD as output } void loop() { DrawBitmap(); } void DrawBitmap() { int horizUnit = 40; // how spaced out horizontally between x pixels? PORTD = 255; // Set to high so we could trigger consistently at this level for (uint8_t band = 0; band < bandMax; band++) // each band is a column of eight pixels { for (uint8_t x = 0; x < 8; x++) // draw 8 horizontal pixels per band { for (uint8_t y = 0; y < yMax; y++) // draw 230 rows of vertical pixels { uint8_t bitAnalogValue = 10+ y; // Offset from 0V so image would be vertically above the almost solid 0V line unsigned char vertByte = pgm_read_byte_near(image + ( (yMax-y) * bandMax + band)); // get the byte representing that row and band if ( ((band*8+x)<xMax) && bitRead(vertByte, 7-x)) PORTD = bitAnalogValue; else PORTD = 0; // if it's within bound and it's ON, move beam to that Y position delayMicroseconds(horizUnit); // Wait a little to allow scope to draw a short horizontal line. } } } PORTD = 0; delay(1000); // Set to 0V and wait before drawing again }

Discussions