Android App Development

Android app development is a quite a cumbersome work to do. It requires a sound knowledge of programming, android and a lot of other things. Surely it is something that requires a lot of hardwork and attention. But fortunately we have another option to choose, MIT App Inventor. Although not for professional developers but still it has such huge variety of tools that it can be used to create a lot of fun for android, can be used to develop things to control through android and it can also be used to make something customized for your phone in case you need. For electrical engineers, it can be of great help as its is easy to build (don't have to spend a lot of time if you are doing some hardware based project) and can create a really cool app to control your hardware.
Here is the link of the site...
MIT App Inventor
Following is a dash board for development. This is used to build interface of the app. On the left hand side is residing a lot of tools that can be dragged on screen placed in the center to add them on it. On extreme left, it shows property panel which is to edit properties of components you have used in your interface. On green ribon at top, it shows app name which in this case is TalkToMe (Space is not allowed), then screen number and an option to add screen.


Here is block panel or place where you program your app. This is visual programming where blocks are given and you have to place them to create logic of your app. On the left is residing all the tools or sytax options you have and in the middle you are placing these blocks to program this app.
Just to learn things, I have created this app wchich only speaks whatever you write in the text box.
It has quite simple logic. If button is pressed, it will speak whatever is written in the box.If mobile is being shaken, it will start yelling at you. It also have some options to go see this blog of mine.

False position method in MATLAB

False position(also called the linear interpolation method) is another well-known bracket-ing method. It is very similar to bisection with the exception that it uses a different strategy
to come up with its new root estimate. Rather than bisecting the interval, it locates the root
by joining f(xl)and f(xu)with a straight line.The intersection of this line with
the xaxis represents an improved estimate of the root. Thus, the shape of the function in-fluences the new root estimate.[1]

%Author: Muhammad Awais
%UET Lahore, Electrical Engineering
%fb/awais12506

function [xr,iteration]=FalsePosition(xl,xu,f,e)
%Find Root of a equation by method of BiSection
%Input: Lower Limit, Upper Limit, Function, Error Tolerance
%Please Insert f as f=@(x)x.^2+9*x+3
%Output: Root of the equation with given precison
%Exception: Give error if Equation is not convergent or roots are dont give
%postive and negative values of the function

iteration=0;     %To see how many iterations, equation took to solve
xr=xl;
error=1;
if  (f(xl)*f(xu)>0)
    disp('Interval have some error')

else
    fprintf('Itr     XR')
     while ( abs(error) > abs(e) ||iteration<=1000 )
        iteration=iteration+1;
        xrOld=xr;
        xr=xu-( (f(xu)*(xl-xu)) /(f(xl)-f(xu)));   %Mid point
        xrNew=xr;
        if f(xl)*f(xr)<0   %if f(xm) is neg, equate xu with xm
            xu=xr;
        else if f(xl)*f(xr)>0 %if f(xm) is pos, equate xl with xm
            xl=xr;
            else            %it means xm is our root
            break
            end
        error=(xrNew-xrOld)/xrNew;   %Error

        end

    end

end
end

Output:



References:
[1] Applied Numerical Methods with MATLAB for Engineers and Scientists by Steven C. Chapra
Berger Chair in Computing and Engineering
Tufts University

A counter with Cortex M3, LM4F120 Launch Pad

It uses a seven segment and a button to make a simple counter. It contains a button and seven segment display. When button is pressed, seven segment will show number one more than previous. After 9 it will again show 0.
It uses a common cathode type Seven Segment in which common point is supply and all the pins are provided with  positive voltage to glow.
Button is with positive logic, means it will be considered on when it will provide input pin a high value.
A function SevenSegment is used to display numbers on this seven Segment. Port B from 1 to 7 is used for seven segment. Following is the output code for seven segment. 

Code:

  1. // ***** 0. Documentation Section *****
  2. // SevenSegment.c
  3. // Runs on LM4F120/TM4C123
  4. // Use  programming structures in C Run on a  Seven Segment and Button
  5. //      Name:       Counter
  6. //      Descrption: As you press button, it will count and show numbers 0-9
  7. //      Date:       Feb 11, 2016
  8. //      Student:    Muhammad Awais 2012-EE-506
  9. //      Class:      UTAustinX: UT.6.03x Embedded Systems - Shape the World
  10. // ***** 1. Pre-processor Directives Section *****
  11. #include "tm4c123gh6pm.h"
  12. //Bit specfic adressing for PE0 and PE1
  13. //base adress of PORTE is 0x40024000
  14. #define SW_PE0   (*((volatile unsigned long *)0x40024004))
  15. // ***** 2. Global Declarations Section *****
  16. // FUNCTION PROTOTYPES: Each subroutine defined
  17. void PORTE_Init(void);
  18. void SevenSeg_Init(void);
  19. void clear7Seg(void);
  20. void SevenSegment(int data);
  21. void Delay1ms(unsigned long msec);
  22. // ***** 3. Subroutines Section *****
  23. //GPIO_PORTE_DATA_R
  24. //GPIO_PORTB_DATA_R
  25. // PE0 connected to positive logic momentary switch using 10k ohm pull down resistor
  26. // PB1-PB7 connected to Common Anode Seven Segment
  27. int main(void){
  28. //**********************************************************************
  29. // The following version tests input on PE0 and output on PE1
  30. //**********************************************************************
  31.   int count=0;
  32.     PORTE_Init();      // Initlizes PORTE for switch
  33.     SevenSeg_Init();   // Initlizes PORTB for Seven Segment
  34.   SevenSegment(0);   // Seven Segment is showing 0 on reset
  35.   while(1)           //Infinte loop
  36.         {
  37.        
  38.             /*
  39.             For Simple Counter Without Button
  40.             for(count;count<=9;count++)
  41.             {
  42.             SevenSegment(count);
  43.                 Delay1ms(1000);
  44.                 clear7Seg();
  45.             }
  46.             */
  47.         if (count>9)                            //When count=9 it makes it zero
  48.         {
  49.             count=0;
  50.             SevenSegment(count);
  51.         }
  52.        
  53.         if(SW_PE0==0x01)                        //If switch is presses
  54.         {
  55.             count=count+1;                          //incremetn counter
  56.             clear7Seg();                                //Clears seven segment to write new data
  57.             SevenSegment(count);                //Writes number on Seven Segment
  58.             Delay1ms(100);              //Dealy for button debouncing and other factors
  59.         }
  60.        
  61.   }
  62. }
  63. /*
  64. Descrption: Initilizes PE0==>Input
  65. Input: None
  66. Output: None
  67. */
  68. void PORTE_Init(void)
  69. {
  70.   volatile unsigned long delay;
  71.   SYSCTL_RCGC2_R |= 0x00000010;      // 1) E clock
  72.   delay = SYSCTL_RCGC2_R;            // delay to allow clock to stabilize    
  73.   GPIO_PORTE_AMSEL_R &= 0x00;        // 2) disable analog function
  74.   GPIO_PORTE_PCTL_R &= 0x00000000;   // 3) GPIO clear bit PCTL  
  75.   GPIO_PORTE_DIR_R &= ~0x01;         // 4.1) PE0 input,
  76.   GPIO_PORTE_AFSEL_R &= 0x00;        // 5) no alternate function      
  77.   GPIO_PORTE_DEN_R |= 0x01;          // 6) enable digital pins PE4-PE1
  78. }
  79. /*
  80. Descrption: Initilizes PB1 to PB7 as output
  81. Input: None
  82. Output: None
  83. */
  84. void SevenSeg_Init(void)
  85. {
  86.   volatile unsigned long delay;
  87.   SYSCTL_RCGC2_R |= 0x00000002;      // 1) B clock
  88.   delay = SYSCTL_RCGC2_R;            // delay to allow clock to stabilize    
  89.   GPIO_PORTB_AMSEL_R &= 0x00;        // 2) disable analog function
  90.   GPIO_PORTB_PCTL_R &= 0x00000000;   // 3) GPIO clear bit PCTL  
  91.   GPIO_PORTB_DIR_R |= 0xFF;          // 4) PB output  
  92.   GPIO_PORTB_AFSEL_R &= 0x00;        // 5) no alternate function      
  93.   GPIO_PORTB_DEN_R |= 0xFF;          // 6) enable digital AT PB
  94. }
  95. /*
  96. Descrption: Clears all 1-7 pins of PortB
  97. Input: None
  98. Output: None
  99. */
  100. void clear7Seg()
  101. {
  102.     GPIO_PORTB_DATA_R=0xff;
  103. }
  104. /*
  105. Descrption: All the pins who will show number on Seven Segment will be zero
  106. It is for common anode type, to make it for common cathode add ~ before all cases
  107. Input: Number to be printed on Seven Segment
  108. Output: None
  109. */
  110. void SevenSegment(int data){
  111.     switch(data)
  112.     {
  113.         case 0: GPIO_PORTB_DATA_R=0x11  ;
  114.         break;
  115.       case 1: GPIO_PORTB_DATA_R=0x7D;
  116.         break;
  117.         case 2: GPIO_PORTB_DATA_R=0x89;
  118.         break;
  119.         case 3: GPIO_PORTB_DATA_R=0x29;
  120.         break;
  121.         case 4: GPIO_PORTB_DATA_R=0x65;
  122.         break;
  123.         case 5: GPIO_PORTB_DATA_R=0x23;
  124.         break;
  125.         case 6: GPIO_PORTB_DATA_R=0x03;
  126.         break;
  127.         case 7: GPIO_PORTB_DATA_R=0x79;
  128.         break;
  129.         case 8: GPIO_PORTB_DATA_R=0x01;
  130.         break;
  131.         case 9: GPIO_PORTB_DATA_R=0x21;
  132.         break;
  133.     }
  134. }
  135. /*
  136. Descrption: Uses time of a instruction to delay time
  137. Almost 1ms for each cycle
  138. Input: Number of ms to delay
  139. Output: None
  140. */
  141. void Delay1ms(unsigned long msec){
  142. // write this function
  143.     unsigned long i;
  144.    
  145.   while(msec > 0){
  146.     i = 13333;  // this number means 1ms
  147.     while(> 0){
  148.       i = i - 1;
  149.     }
  150.     msec = msec - 1; // decrements every 1 ms
  151.   }
  152. }

Practical Implementation:

A counter without button


A seven Segment code written in Energia:

Energia is a software that is used for lauch pad to write arduino like code. Here is a code for Seven Segment in Energia.\

/*
 Seven segment display
  Muhammad Awais fb/awais12506
  
  Hardware Required:
  * LaunchPad with an LED
  *Seven segment
  *Connecting wires
  
 .
*/

// most launchpads have a red LED
int A=A2;
int B=A3;
int C=A4;
int D=A1;
int E=A0;
int FI=A5;
int G=7;

//see pins_energia.h for more LED definitions

  
// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(FI,OUTPUT);
  pinMode(G, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  
    setOff();
    sendData(9);
 for(int i=0;i<10;i++)
 {
sendData(i);
delay(1000);
setOff();
 }
}
void sendData(int num)
{
  switch (num)
  {
    case 1: 
    digitalWrite(FI,LOW);
    digitalWrite(E, LOW);
    break;
    case 2:
    digitalWrite(A, LOW);
    digitalWrite(B, LOW);
    digitalWrite(G, LOW);
    digitalWrite(E, LOW);
    digitalWrite(D, LOW);
    break;
    case 3:
    digitalWrite(A, LOW);
    digitalWrite(B, LOW);
    digitalWrite(G, LOW);
    digitalWrite(C, LOW);
    digitalWrite(D, LOW);
    break;
    case 4:
    digitalWrite(FI, LOW);
    digitalWrite(G, LOW);
    digitalWrite(B, LOW);
    digitalWrite(C, LOW);
    
    break;
    case 5:
    digitalWrite(A, LOW);
    digitalWrite(FI, LOW);
    digitalWrite(G, LOW);
    digitalWrite(C, LOW);
    digitalWrite(D, LOW);
    break;
    case 6:
    digitalWrite(A, LOW);
    digitalWrite(FI, LOW);
    digitalWrite(G, LOW);
    digitalWrite(C, LOW);
    digitalWrite(D, LOW);
    digitalWrite(E, LOW);
    break;
     case 7:
    digitalWrite(A, LOW);
    digitalWrite(B, LOW);
    digitalWrite(C, LOW);
    break;
    case 8:
    digitalWrite(A, 0);
    digitalWrite(B, 0);
    digitalWrite(C, 0);
    digitalWrite(D, 0);
    digitalWrite(E, 0);
    digitalWrite(FI,0);
    digitalWrite(G, 0);
    case 9:
    digitalWrite(A, LOW);
   // digitalWrite(B, 0);
    //digitalWrite(C, 0);
    //digitalWrite(FI,0);
    //digitalWrite(G, 0);
    case 0:
    digitalWrite(A, 0);
    digitalWrite(B, 0);
    digitalWrite(C, 0);
    digitalWrite(D, 0);
    digitalWrite(E, 0);
    digitalWrite(FI,0);

  }
}
void setOff()
{
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(FI,HIGH);
    digitalWrite(G, HIGH);
    
}

void setOn()
{
    digitalWrite(A, 0);
    digitalWrite(B, 0);
    digitalWrite(C, 0);
    digitalWrite(D, 0);
    digitalWrite(E, 0);
    digitalWrite(FI,0);
    digitalWrite(G, 0);
    
}