From 4a69d2542855658d0386154047d8cc7eb26dfcd9 Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Mon, 21 Nov 2016 15:28:26 -0500
Subject: [PATCH] Fully functional, working a8

---
 a8.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/a8.c b/a8.c
index c0ad6d2..4075584 100644
--- a/a8.c
+++ b/a8.c
@@ -11,6 +11,7 @@ int main(void)
     P1DIR = BIT6;                           // Set P2.6 for output.
     P1SEL = BIT6|BIT4;                      // BIT4 analog input (channel 4)
     P2DIR = BIT1|BIT5;                      // Set P2.1 and 2.2 for output.
+    P2SEL = BIT1|BIT5;
 
     // Set interupts.
     P1REN = BIT3;                           // Sets pullup state. Helps make button pushing be more consistent.
@@ -29,6 +30,9 @@ int main(void)
     TA1CCR1  = 0;                           // start off
     TA1CCTL1 = OUTMOD_7;                    // reset/set output mode
 
+    TA1CCR2  = 0;
+    TA1CCTL2 = OUTMOD_7;
+
     ADC10CTL1 = INCH_4 | ADC10DIV_3;        // ??ADC10 channel 4, clock divider 3
     ADC10CTL0 = SREF_0 | ADC10SHT_3 |       // ??VCC/VSS ref, 64 x ADC10CLKs
                ADC10ON | ADC10IE;           // ??ADC10 enable, ADC10 interrupt enable
@@ -45,27 +49,34 @@ int main(void)
 
 
         // ADC10MEM is a 10 bit number. &-ing with 0x3F8 somehow just throws away the bottom 3 bits?
-        if (colorChange = 'r') {
+        if (colorChange == 'r') {
             TA0CCR1 = ADC10MEM & 0x3F8;     // ADC10MEM is probably a value set from sampling, a few lines above?
-                                            // This will assign that value to the TA0CCR1 register, which corresponds to red?
+                                            // This will assign that value to the TA0CCR1 register, which corresponds to P1.6 aka red.
         } else if (colorChange == 'g') {
-            TA1CCR1 = ADC10MEM & 0x3F8;     // assigns the value held in ADC10MEM to the TA0CCR1 register
+            TA1CCR2 = ADC10MEM & 0x3F8;     // assigns the value held in ADC10MEM to the TA0CCR1 register
+                                            // This will assign that value to the TA0CCR?? register, which corresponds to P2.5 aka green.
         } else {
-            //TA0CCR1 = ADC10MEM & 0x3F8;     // assigns the value held in ADC10MEM to the TA0CCR1 register
+            TA1CCR1 = ADC10MEM & 0x3F8;     // assigns the value held in ADC10MEM to the TA0CCR2 register
+                                            // This will assign that value to the TA0CCR1 register, which corresponds to P2.1 aka blue.
         }
     }
 
     return 0;
 }
  
-// ADC10 interrupt service routine
+// ADC10 interrupt service routine. Aka reads current resistor value.
 #pragma vector=ADC10_VECTOR
 __interrupt void ADC10_ISR (void)
 {
-
     // Turns cpu register back on.
     __bic_SR_register_on_exit(CPUOFF);      // wake up
+}
 
+
+// Actual button interrupt.
+#pragma vector=PORT1_VECTOR
+__interrupt void button (void)
+{
     // If red, change to green. If green, change to blue. If blue, change to red.
     if (colorChange == 'r') {
         colorChange = 'g';
@@ -75,6 +86,5 @@ __interrupt void ADC10_ISR (void)
         colorChange = 'r';
     }
     P1IFG &= ~BIT3;                         // Enable interupts on 1.3
-
 }
 
-- 
GitLab