Skip to content

Instantly share code, notes, and snippets.

@rtyler
Last active Nov 9, 2018
Embed
What would you like to do?
with MicroBit.Display;
with MicroBit.SPI;
with MicroBit.Buttons; use MicroBit.Buttons;
with MicroBit.Time;
with HAL.Bitmap;
with ST7735R; use ST7735R;
with nRF51.Device;
procedure Main is
Screen : ST7735R.ST7735R_Screen (
Port => MicroBit.SPI.Controller,
CS => nRF51.Device.P16'Access,
RS => nRF51.Device.P12'Access,
RST => nRF51.Device.P08'Access,
Time => MicroBit.Time.HAL_Delay);
procedure Initialize_Display (Screen : in out ST7735R.ST7735R_Screen) is
begin
Initialize (Screen);
Screen.Set_Memory_Data_Access (
Color_Order => RGB_Order,
Vertical => Vertical_Refresh_Top_Bottom,
Horizontal => Horizontal_Refresh_Left_Right,
Row_Addr_Order => Row_Address_Bottom_Top,
Column_Addr_Order => Column_Address_Right_Left,
Row_Column_Exchange => False);
Screen.Set_Pixel_Format (Pixel_16bits);
Set_Frame_Rate_Normal (Screen,
RTN => 16#01#,
Front_Porch => 16#2C#,
Back_Porch => 16#2D#);
Set_Frame_Rate_Idle (Screen,
RTN => 16#01#,
Front_Porch => 16#2C#,
Back_Porch => 16#2D#);
Set_Frame_Rate_Partial_Full (Screen,
RTN_Part => 16#01#,
Front_Porch_Part => 16#2C#,
Back_Porch_Part => 16#2D#,
RTN_Full => 16#01#,
Front_Porch_Full => 16#2C#,
Back_Porch_Full => 16#2D#);
Set_Inversion_Control (Screen,
Normal => Line_Inversion,
Idle => Line_Inversion,
Full_Partial => Line_Inversion);
Set_Power_Control_1 (Screen,
AVDD => 2#101#, -- 5
VRHP => 2#0_0010#, -- 4.6
VRHN => 2#0_0010#, -- -4.6
MODE => 2#10#); -- AUTO
Set_Power_Control_2 (Screen,
VGH25 => 2#11#, -- 2.4
VGSEL => 2#01#, -- 3*AVDD
VGHBT => 2#01#); -- -10
Set_Power_Control_3 (Screen, 16#0A#, 16#00#);
Set_Power_Control_4 (Screen, 16#8A#, 16#2A#);
Set_Power_Control_5 (Screen, 16#8A#, 16#EE#);
Set_Vcom (Screen, 16#E#);
Set_Address (Screen,
X_Start => 0,
X_End => 127,
Y_Start => 0,
Y_End => 159);
Turn_On (Screen);
Initialize_Layer (
Display => Screen,
Layer => 1,
Mode => HAL.Bitmap.RGB_565,
X => 0,
Y => 0,
Width => 160,
Height => 128);
end Initialize_Display;
begin
MicroBit.SPI.Initialize;
MicroBit.Display.Display ('o');
Initialize_Display (Screen);
Screen.Hidden_Buffer (1).Set_Source (HAL.Bitmap.Red);
Screen.Hidden_Buffer (1).Fill_Rect (((0, 0), 50, 50));
Screen.Update_Layer (1);
MicroBit.Display.Display ('x');
loop
MicroBit.Display.Display ("boo!");
if MicroBit.Buttons.State (Button_A) = Pressed then
MicroBit.Display.Clear;
-- If button A is pressed
-- Display the letter A
MicroBit.Display.Display ('A');
elsif MicroBit.Buttons.State (Button_B) = Pressed then
-- If button B is pressed
-- Display the letter B
MicroBit.Display.Display ('B');
end if;
MicroBit.Time.Delay_Ms (200);
end loop;
end Main;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment