Skip to content

Categories:

Structure of an Ada Mindstorms Program: What Makes Main?

In Ada, a ‘main’ procedure, at which sequential execution begins, is not made so by using a specially-reserved name, as in C-family languages; the familiar ‘main(void)’ or ‘main(int charc, char * argv[])’ functions. Instead, a procedure is treated as a main procedure (there need not be only one) iff:

  1. It is not contained within a package (as packages are used to store library code)
  2. It is nullary (i.e. takes no arguments)

This was a topic of some confusion for our team, as no tutorials we read made this explicit.

Posted in Uncategorized.

Ultrasonic Sensor

with Ada.Real_Time; use Ada.Real_Time;
with NXT.Display;   use NXT.Display;
with NXT.AVR;
with NXT.Ultrasonic_Sensors; use NXT.Ultrasonic_Sensors;
with NXT.Ultrasonic_Sensors.Ctors;
 
procedure Ultrasonic_Test is
  use NXT;
  Result : Button_Id;
  Cur_Sensor : NXT.Ultrasonic_Sensors.Ultrasonic_Sensor := NXT.Ultrasonic_Sensors.Ctors.Make(Sensor_1);
  Distance : Natural range 0..255;
begin
NXT.AVR.Await_Data_Available;
Put_Line ("Ultrasonic Test: Ping!");
  loop
    Ping(Cur_Sensor);
    Get_Distance(Cur_Sensor, Distance);
    if (Distance = 255) then
      Clear_Screen_Noupdate;
      Put_Noupdate("Nothing in sight!");
      Screen_Update;
    else
      Clear_Screen_Noupdate;
      Put_Noupdate("Hi Ken! Something is ");
      Put_Noupdate(Distance);
      Put_Noupdate(" cm away!");
      Screen_Update;
    end if;
  end loop;
end Ultrasonic_Test;

Posted in Uncategorized.

Light Sensors

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
with NXT.Display;   use NXT.Display;
with NXT.AVR;
with NXT.Light_Sensors; use NXT.Light_Sensors;
with NXT.Light_Sensors.Ctors; use NXT.Light_Sensors.Ctors;
 
procedure light_test is
  use NXT;
  Light  :  Integer;
  Light_Sensor_1  : Light_Sensor := make(Sensor_1, True);
begin
  loop
    Clear_Screen_Noupdate;
    Light := NXT.Light_Sensors.Light_Value (Light_Sensor_1);
    Put_Noupdate(Light);
    Screen_Update;
  end loop;
end light_test;

Posted in Uncategorized.

Hello world!

1
2
3
4
5
6
7
8
9
with Ada.Real_Time; use Ada.Real_Time;
with NXT.Display;   use NXT.Display;
with NXT.AVR;
 
procedure helloworld is
  use NXT;
begin
  Put_Line ("Hello world!");
end helloworld;

Posted in Uncategorized.