Skip navigation

behavior

Cinomadic > code > behavior

When the user is pressing a button the system has to been able to decode his action and traduce thi input in a action onto the screen. The response of the phisical user behavior (press “a” button) are menage with the keyPressed preset function.
In this page are written all the keyPressed functions. The void keyPressed() contains just six functions which are related to other sub functions. The main one is written at last.

If the user is on the logo and is pressing softkey2 appears the main manu:
void keyPressedLogo (){
if (keyCode == SOFTKEY2){
sectionMode =  SECTION_MAINMENU;
}
}

On the main manu it is possible scroll orizontal, to right, left and press one of the four main option and go into each section:
void keyPressedSectionMainmenu(){
if focused in option A = “EVENTS” section:
if  (mainmenuFocus == MAINMENU_EVENTS){
if pressed right:
if (keyCode == RIGHT){
moves focus to option B = “SAERCH EVENTS” section:
mainmenuFocus = MAINMENU_SEARCH;
}
softkey2 is pressed:
else if (keyCode == SOFTKEY2){
shows “EVENTS”:
sectionMode = SECTION_EVENTS;
}
}
if focused in option A = main menu “SEARCH EVENTS”:
else if  (mainmenuFocus == MAINMENU_SEARCH) {
if pressed left:
if (keyCode == LEFT){
moves focus to option B = main menu “EVENTS:
mainmenuFocus = MAINMENU_EVENTS;
}
if pressed right:
else if (keyCode == RIGHT){
moves focus to option B = main menu “MY EVENTS”:
mainmenuFocus = MAINMENU_MYEVENTS;
}
if softkey2 is pressed:
else if (keyCode == SOFTKEY2){
shows “SEARCH EVENTS”:
sectionMode = SECTION_SEARCH;
}
}

etc.

////////////////////////////////////////////////////////////////

This one controlls the “EVENTS” section. We worked it with the arrays. We have seven items into the images array.
void keyPressedSectionEvents(){
if (keyCode == SOFTKEY1){
sectionMode = SECTION_MAINMENU;
}
if goes left it will shift from item 0 to 1 and so on:
if(keyCode == LEFT){
if (0 == eventsMode){
eventsMode = 6;
}
else{
–eventsMode;
}
eventsModeMovie = 0;
}

contrary, if it goes to right the first shown item will be the seventh, sixth, fifth…
if(keyCode == RIGHT){
if (eventsMode == 6){
eventsMode = 0;
}
else{
++eventsMode;
}
eventsModeMovie = 0;
}
if goes up
and it starts with the first item, the shown screen will be the seventh, sixth..:
if(keyCode == UP){

if (0 == eventsModeMovie){

eventsModeMovie = (events_images_counts[eventsMode] - 1);
}
else{
–eventsModeMovie;
}
}

if it goes down,
it will starts from the first one and number will increased:
if(keyCode == DOWN){

if (eventsModeMovie == (events_images_counts[eventsMode] - 1)){
eventsModeMovie = 0;
}
else{
++eventsModeMovie;
}
}
}

////////////////////////////////////////////////////////////////

This is for the “SEARCH EVENTS” section:
void keyPressedSectionSearch(){

it records that the key is pressed:
keyIsPressed = true;
if it is on the first stage and softkey2 is pressed, it shows the map:

if(searchMode == SCREEN_POPUP){
if(keyCode == SOFTKEY2){
searchMode = SCREEN_MAPPA;
}

it softkey1 is pressed it returns to the main manu:

else if (keyCode == SOFTKEY1){
sectionMode =  SECTION_MAINMENU;
}
}

if from map softkey2 is pressed and it showing the pop up, it returns to main menu:

else if (searchMode == SCREEN_MAPPA){
if(keyCode == SOFTKEY2){
if(showingFumetto){
sectionMode = SECTION_EVENTS;
eventsMode = 0;
eventsModeMovie = 0;
}

otherwise the pop up:

else{
searchMode = SCREEN_POPUP;
}
}
else if(keyCode == SOFTKEY1){
sectionMode = SECTION_MAINMENU;
}
}
}

Here we declared the functions which update the light position into the void setup()
int calculateDistance(int x1, int y1, int x2, int y2){
int dist2X = itofp(sq(x1 - x2));
int dist2Y = itofp(sq(y1 - y2));
return fptoi(sqrt(dist2X + dist2Y));
}

////////////////////////////////////////////////////////////////

“MY EVENTS” section:
void keyPressedSectionMyevents(){
if (myeventsMode == MYEVENTS_MENU){

if focus on the event 1 and goes down, it will show event 2:
if (myeventsmenuFocus == MYEVENTS_MENU_EVENT0){
if (keyCode == DOWN){
myeventsmenuFocus = MYEVENTS_MENU_EVENT1;
}
if pressed sotfkey2 the variable myeventsMode shift to the lawer lavel and will show the datail about event 1
else if(keyCode == SOFTKEY2){
myeventsMode = MYEVENTS_DETAIL;
myeventsdetailMode = MYEVENTS_DETAIL_EVENT0;
}
}

if focus on the event 2, and goes down, it will show event 3:

else  if(myeventsmenuFocus == MYEVENTS_MENU_EVENT1){
if (keyCode == DOWN){
myeventsmenuFocus = MYEVENTS_MENU_EVENT2;
}

if goes up it shows event 1:

else if (keyCode == UP){
myeventsmenuFocus = MYEVENTS_MENU_EVENT0;
}
else if(keyCode == SOFTKEY2){
myeventsMode = MYEVENTS_DETAIL;
myeventsdetailMode = MYEVENTS_DETAIL_EVENT1;
}
}
etc.

////////////////////////////////////////////////////////////////

In “TORCH MODE” are liked three consequetials, opening, info and map, which are worte out of this block:

void keyPressedSectionTorch(){
torchKeyIsPressed = true;
if(torchMode == TORCH_OPENING){
torchKeyPressedOpening();
}
else if(torchMode == TORCH_INFO){
torchKeyPressedInfo();
}
else if(torchMode == TORCH_MAP){
torchKeyPressedMap();
}
}

void torchKeyPressedOpening(){
if(keyCode == SOFTKEY1){
sectionMode =  SECTION_MAINMENU;
}
etc.

////////////////////////////////////////////////////////////////

This is the main keypressed which has to contain all the keypressed fragmats above:
void keyPressed(){

if(sectionMode == SECTION_LOGO){
keyPressedLogo();
}
else if(sectionMode == SECTION_MAINMENU){
keyPressedSectionMainmenu();
}
else if (sectionMode == SECTION_EVENTS){
keyPressedSectionEvents();
}
else if (sectionMode == SECTION_SEARCH){
keyPressedSectionSearch();
}
else if (sectionMode == SECTION_MYEVENTS){
keyPressedSectionMyevents();
}
else if (sectionMode == SECTION_TORCH){
keyPressedSectionTorch();
}
}

The last small piece is necessary to “TORCH MODE”. It records whether or not the key is pressed:
boolean keyIsPressed = false;

void keyReleased(){
keyIsPressed = false;
torchKeyIsPressed = false;
}

| Cinomadic | how it works … | circuito off | corporate identity | users + stakeholders | technologies | code … > logic > graphics > behavior | early investigations | credits | downloads |