Charles Tritt / Mbed 2 deprecated PowOf3

Dependencies:   mbed

Fork of aReadConditional by Charles Tritt

Files at this revision

API Documentation at this revision

Comitter:
CSTritt
Date:
Mon Sep 25 15:09:48 2017 +0000
Parent:
4:acc6be2bbe21
Commit message:
Initial version.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Sep 22 19:51:46 2017 +0000
+++ b/main.cpp	Mon Sep 25 15:09:48 2017 +0000
@@ -1,39 +1,29 @@
 /*
-    Project: aReadConditional (for analog read conditional)
+    Project: PowOf3
     File: main.cpp
     
-    Reads from analog input, streams ASCII text to std serial using printf and
-    lights onboard LED. Also demonstrates use of floating point literal suffix
-    toeliminate warning and int constants for HIGH and LOW.
-    
+    Simple powers of 3 program. Demonstrates for loops and arrays.
+  
     Written by: Dr. C. S. Tritt
-    Created: 3/27/17 (v. 1.1)
+    Created: 9/25/17 (v. 1.0)
     
 */
 #include "mbed.h"
 
-const int HIGH = 1; // Optional, but makes code more readable.
-const int LOW = 0; // Optional, but makes code more readable.
- 
+Serial pc(USBTX, NC, 9600); // Serial transmit only @ 9600 baud.
 AnalogIn analog_value(A0); // Construct AnalogIn object called analog_value.
- 
-DigitalOut led(LED1); // Construct DigitalOut object called led.
 
 int main() {
-    float value; // Value to be read and sent to serial port.
+     
+    printf("\nPowers of 3 Demonstration (v. 1.0)\n"); // Identify program.
     
-    printf("\nAnalogIn example\n"); // Identify program.
+    const int SIZE = 10; // Number of array elements.
     
-    while(true) {
-        value = analog_value.read(); // Read the analog input value (0 to 1)
-        printf("Value = %f\n", value); // Send value as text via serial port.
-        if (value > 0.5f) { // Activate built-in LED. The f is optional.
-          led.write(HIGH);
-        }
-        else {
-          led.write(LOW);
-        }
-        printf("LED = %d\n", (int) led.read()); // Send LED state via serial. 
-        wait(0.5); // Half a second (500 mS).
+    int i; // Loop counter.
+    int p[SIZE]; // Number of elements.
+    
+    for(i = 0; i <= SIZE - 1; i++) {
+        p[i] = (int) pow(3.0, (double) i);
+        pc.printf(" i = %i and 3^i = %i.\n", i, p[i]);
     }
 }
\ No newline at end of file